Module: FormFactor

Defined in:
lib/form_factor/form_factor.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_templateObject



36
37
38
# File 'lib/form_factor/form_factor.rb', line 36

def FormFactor.default_template
  @default_template ||= Hash.new(:scaffold)
end

.included(mod) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/form_factor/form_factor.rb', line 2

def self.included(mod)
  mod.helper :form_factor
  mod.helper_method :ff_template, :ff_included_ss, :ff_included_js

  def ff_template options
    t = instantiate_template options
    ff_include_ss t.stylesheets
    ff_include_js t.javascripts
    t
  end

  def ff_include_ss files
    [files].flatten.compact.each {|f| (@included_stylesheets ||= []) << f }
  end

  def ff_include_js files
    [files].flatten.compact.each {|f| (@included_javascripts ||= []) << f }
  end

  def ff_included_ss 
    (@included_stylesheets || []).uniq
  end

  def ff_included_js 
    (@included_javascripts || []).uniq
  end

  def instantiate_template options
    name = options[:template] || FormFactor.default_template[options[:format]]
    template_name = name.to_s + "_template"
    template_name.camelize.constantize.new(options)
  end
end

Instance Method Details

#ff_include_js(files) ⇒ Object



17
18
19
# File 'lib/form_factor/form_factor.rb', line 17

def ff_include_js files
  [files].flatten.compact.each {|f| (@included_javascripts ||= []) << f }
end

#ff_include_ss(files) ⇒ Object



13
14
15
# File 'lib/form_factor/form_factor.rb', line 13

def ff_include_ss files
  [files].flatten.compact.each {|f| (@included_stylesheets ||= []) << f }
end

#ff_included_jsObject



25
26
27
# File 'lib/form_factor/form_factor.rb', line 25

def ff_included_js 
  (@included_javascripts || []).uniq
end

#ff_included_ssObject



21
22
23
# File 'lib/form_factor/form_factor.rb', line 21

def ff_included_ss 
  (@included_stylesheets || []).uniq
end

#ff_template(options) ⇒ Object



6
7
8
9
10
11
# File 'lib/form_factor/form_factor.rb', line 6

def ff_template options
  t = instantiate_template options
  ff_include_ss t.stylesheets
  ff_include_js t.javascripts
  t
end

#instantiate_template(options) ⇒ Object



29
30
31
32
33
# File 'lib/form_factor/form_factor.rb', line 29

def instantiate_template options
  name = options[:template] || FormFactor.default_template[options[:format]]
  template_name = name.to_s + "_template"
  template_name.camelize.constantize.new(options)
end