Class: Fidelity::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/fidelity/builder.rb

Constant Summary collapse

COLUMN_SIZE =
%w(zero one two three four five six seven eight nine ten eleven twelve)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, &block) ⇒ Builder

Returns a new instance of Builder.



7
8
9
10
# File 'lib/fidelity/builder.rb', line 7

def initialize template, &block
  @template = template
  @widget_helpers = Fidelity::WidgetHelper.new
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



6
7
8
# File 'lib/fidelity/builder.rb', line 6

def template
  @template
end

#widget_helpersObject (readonly)

Returns the value of attribute widget_helpers.



6
7
8
# File 'lib/fidelity/builder.rb', line 6

def widget_helpers
  @widget_helpers
end

Instance Method Details

#column(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fidelity/builder.rb', line 26

def column *args
  options = args.extract_options!
  size = args.shift
  classes = ['grid-column']
  if args.delete(:border)
    classes << 'grid-column-border'
  end
  if args.delete(:shaded)
    classes << 'grid-column-shaded'
  end
  template.('div', :class => classes.join(' '), :style => "-webkit-box-flex:#{size}") do
    yield
  end
end

#grid(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fidelity/builder.rb', line 12

def grid *args
  options = args.extract_options!
  classes = ['grid']
  if args.delete(:visible) or options.delete(:visible)==true
    classes << 'grid-visible'
  end
  if not options.delete(:padded)===false
    classes << 'grid-padded'
  end
  template.('div', :class => classes.join(' ')) do
    yield
  end
end

#row(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fidelity/builder.rb', line 41

def row *args
  options = args.extract_options!
  classes = ['grid-row']
  if args.delete(:border)
    classes << 'grid-row-border'
  end
  if args.delete(:shaded)
    classes << 'grid-row-shaded'
  end
  template.('div', :class => classes.join(' ')) do
    yield
  end
end

#widget(name = 'heading', options = {}, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fidelity/builder.rb', line 55

def widget name='heading', options={}, &block
  name = name.to_s
  relative_widget_path = File.join('app', 'fidelity', 'widgets', name)
  if view_templates = extract_file_path(File.join(relative_widget_path, 'views','index.*')) and not view_templates.blank?
    include_widget_helpers(File.join('app', 'fidelity', 'helpers','*.rb'), File.join(relative_widget_path,'helpers','*.rb'))
    builder = nil
    block = if block_given? 
      if klass = extract_file_path(File.join(relative_widget_path, "#{name}.rb")) and not klass.blank?
        require klass.first
        builder = "fidelity/widget/#{name}".classify.constantize.new(template, options)
        template.capture do
          block.call(builder)
        end
      else
        template.capture(&block)
      end
      
    else
      nil
    end
    locals = {name.to_sym => builder, :fidelity_helper => widget_helpers, :block => block, :options => options, :view_path => Fidelity::Engine.root.join(relative_widget_path, 'views')}
    template.render(:template => view_templates.first, :locals => locals)
    
  else
    raise ActionController::RoutingError, "No such widget: #{name}"
  end      
end