Class: Fidelity::Builder
- Inherits:
-
Object
- Object
- Fidelity::Builder
- 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
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#widget_helpers ⇒ Object
readonly
Returns the value of attribute widget_helpers.
Instance Method Summary collapse
- #column(*args) ⇒ Object
- #grid(*args) ⇒ Object
-
#initialize(template, &block) ⇒ Builder
constructor
A new instance of Builder.
- #row(*args) ⇒ Object
- #widget(name = 'heading', options = {}, &block) ⇒ Object
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
#template ⇒ Object (readonly)
Returns the value of attribute template.
6 7 8 |
# File 'lib/fidelity/builder.rb', line 6 def template @template end |
#widget_helpers ⇒ Object (readonly)
Returns the value of attribute widget_helpers.
6 7 8 |
# File 'lib/fidelity/builder.rb', line 6 def @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 = args. 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.content_tag('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 = args. classes = ['grid'] if args.delete(:visible) or .delete(:visible)==true classes << 'grid-visible' end if not .delete(:padded)===false classes << 'grid-padded' end template.content_tag('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 = args. classes = ['grid-row'] if args.delete(:border) classes << 'grid-row-border' end if args.delete(:shaded) classes << 'grid-row-shaded' end template.content_tag('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 name='heading', ={}, &block name = name.to_s = File.join('app', 'fidelity', 'widgets', name) if view_templates = extract_file_path(File.join(, 'views','index.*')) and not view_templates.blank? (File.join('app', 'fidelity', 'helpers','*.rb'), File.join(,'helpers','*.rb')) builder = nil block = if block_given? if klass = extract_file_path(File.join(, "#{name}.rb")) and not klass.blank? require klass.first builder = "fidelity/widget/#{name}".classify.constantize.new(template, ) template.capture do block.call(builder) end else template.capture(&block) end else nil end locals = {name.to_sym => builder, :fidelity_helper => , :block => block, :options => , :view_path => Fidelity::Engine.root.join(, 'views')} template.render(:template => view_templates.first, :locals => locals) else raise ActionController::RoutingError, "No such widget: #{name}" end end |