Class: Trellis::CoreLibrary::Grid
- Inherits:
-
Trellis::Component
- Object
- Trellis::Component
- Trellis::CoreLibrary::Grid
- Defined in:
- lib/trellis/component_library/grid.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#counter_method ⇒ Object
readonly
Returns the value of attribute counter_method.
-
#counter_method_arguments ⇒ Object
readonly
Returns the value of attribute counter_method_arguments.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#retrieve_block ⇒ Object
readonly
Returns the value of attribute retrieve_block.
-
#sort_properties ⇒ Object
readonly
Returns the value of attribute sort_properties.
-
#source ⇒ Object
Returns the value of attribute source.
Attributes inherited from Trellis::Component
Instance Method Summary collapse
- #add_command(options = []) ⇒ Object
-
#columns(*syms) ⇒ Object
must be called before rendering.
-
#initialize ⇒ Grid
constructor
A new instance of Grid.
-
#on_page(page) ⇒ Object
event handlers.
- #on_sort(property) ⇒ Object
- #retrieve_method(&block) ⇒ Object
- #size_accessor(symbol, args) ⇒ Object
- #sort_by(*syms) ⇒ Object
- #sort_by_all_except(*syms) ⇒ Object
Methods inherited from Trellis::Component
add_class_scripts_to_page, add_class_styles_to_page, add_document_modifications_to_page, add_script_links_to_page, add_scripts_to_page, add_style_links_to_page, add_styles_to_page, contained_in, depends_on, field, get_component, inherited, is_stateful, #load_component_session_information, page_contribution, register_with_tag_context, render, #save_component_session_information, tag_name
Constructor Details
#initialize ⇒ Grid
Returns a new instance of Grid.
52 53 54 55 56 |
# File 'lib/trellis/component_library/grid.rb', line 52 def initialize @properties = [] @sort_properties = [] @commands = [] end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
44 45 46 |
# File 'lib/trellis/component_library/grid.rb', line 44 def commands @commands end |
#counter_method ⇒ Object (readonly)
Returns the value of attribute counter_method.
45 46 47 |
# File 'lib/trellis/component_library/grid.rb', line 45 def counter_method @counter_method end |
#counter_method_arguments ⇒ Object (readonly)
Returns the value of attribute counter_method_arguments.
46 47 48 |
# File 'lib/trellis/component_library/grid.rb', line 46 def counter_method_arguments @counter_method_arguments end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
43 44 45 |
# File 'lib/trellis/component_library/grid.rb', line 43 def properties @properties end |
#retrieve_block ⇒ Object (readonly)
Returns the value of attribute retrieve_block.
47 48 49 |
# File 'lib/trellis/component_library/grid.rb', line 47 def retrieve_block @retrieve_block end |
#sort_properties ⇒ Object (readonly)
Returns the value of attribute sort_properties.
48 49 50 |
# File 'lib/trellis/component_library/grid.rb', line 48 def sort_properties @sort_properties end |
#source ⇒ Object
Returns the value of attribute source.
41 42 43 |
# File 'lib/trellis/component_library/grid.rb', line 41 def source @source end |
Instance Method Details
#add_command(options = []) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/trellis/component_library/grid.rb', line 65 def add_command(=[]) # extract options name = [:name] if page = [:page] if context = [:context] if image = [:image] if @commands << lambda do |tag, object| tid = tag.attr['tid'] value = object.send(context.to_sym) url_root = tag.globals.page.class.url_root page = tag.globals.page.class.name unless page href = Trellis::DefaultRouter.to_uri(:url_root => url_root, :page => page, :event => name, :source => tid, :value => value) %{ <a href="#{href}"> <img src='#{image}'/> </a> } end end |
#columns(*syms) ⇒ Object
must be called before rendering
59 60 61 62 63 |
# File 'lib/trellis/component_library/grid.rb', line 59 def columns(*syms) syms.each do |sym| @properties << sym end end |
#on_page(page) ⇒ Object
event handlers
113 114 115 |
# File 'lib/trellis/component_library/grid.rb', line 113 def on_page(page) @page_position = page.to_i # must use the cohersion built in capabilities end |
#on_sort(property) ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/trellis/component_library/grid.rb', line 117 def on_sort(property) to_sym = property.to_sym if @sort_properties.include?(to_sym) if @sorted_by != to_sym @sorted_by = to_sym else @sort_direction = @sort_direction == :ascending ? :descending : :ascending end end end |
#retrieve_method(&block) ⇒ Object
107 108 109 |
# File 'lib/trellis/component_library/grid.rb', line 107 def retrieve_method(&block) @retrieve_block = block end |
#size_accessor(symbol, args) ⇒ Object
103 104 105 |
# File 'lib/trellis/component_library/grid.rb', line 103 def size_accessor(symbol, args) @counter_method, @counter_method_arguments = symbol, args end |
#sort_by(*syms) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/trellis/component_library/grid.rb', line 95 def sort_by(*syms) unless syms.first == :all @sort_properties = syms else @sort_properties = @properties end end |
#sort_by_all_except(*syms) ⇒ Object
91 92 93 |
# File 'lib/trellis/component_library/grid.rb', line 91 def sort_by_all_except(*syms) @sort_properties = @properties.reject { |property| syms.includes?(property)} end |