File List
29 | 38 |-
41 |
42 |
43 |
- README 44 | 45 | 46 |
├── doc ├── css │ ├── common.css │ ├── full_list.css │ └── style.css ├── frames.html ├── file_list.html ├── class_list.html ├── top-level-namespace.html ├── Attrtastic │ ├── Railtie.html │ ├── SemanticAttributesHelper.html │ └── SemanticAttributesBuilder.html ├── method_list.html ├── Attrtastic.html ├── _index.html ├── index.html ├── file.README.html └── js │ ├── full_list.js │ └── app.js ├── lib ├── attrtastic │ ├── version.rb │ ├── railtie.rb │ ├── semantic_attributes_helper.rb │ └── semantic_attributes_builder.rb └── attrtastic.rb ├── .gitignore ├── .document ├── init.rb ├── Gemfile ├── Rakefile ├── LICENSE ├── Gemfile.lock ├── attrtastic.gemspec ├── README.md └── test ├── test_semantic_attributes_helper.rb ├── helper.rb ├── test_attrtastic.rb ├── test_attribute.rb └── test_attributes.rb /doc/css/common.css: -------------------------------------------------------------------------------- 1 | /* Override this file with custom rules */ -------------------------------------------------------------------------------- /lib/attrtastic/version.rb: -------------------------------------------------------------------------------- 1 | module Attrtastic 2 | VERSION = "0.4.3" 3 | end 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## PROJECT::SPECIFIC 2 | .yardoc 3 | 4 | pkg/* 5 | *.gem 6 | .bundle 7 | -------------------------------------------------------------------------------- /.document: -------------------------------------------------------------------------------- 1 | README.rdoc 2 | lib/**/*.rb 3 | bin/* 4 | features/**/*.feature 5 | LICENSE 6 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require "attrtastic" 2 | ActionView::Base.send(:include, Attrtastic::SemanticAttributesHelper) 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Specify your gem's dependencies in attrtastic.gemspec 4 | gemspec 5 | 6 | gem "rake", '~> 0.9.2.2' 7 | -------------------------------------------------------------------------------- /lib/attrtastic/railtie.rb: -------------------------------------------------------------------------------- 1 | require 'attrtastic' 2 | require 'rails' 3 | 4 | module Attrtastic 5 | class Railtie < Rails::Railtie 6 | initializer 'attrtastic.initialize', :after => :after_initialize do 7 | ActionView::Base.send :include, Attrtastic::SemanticAttributesHelper 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /doc/frames.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 |
6 | 7 |79 | 80 | 81 | Modules: Attrtastic 82 | 83 | 84 | 85 | 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |84 | 85 | 86 | Modules: SemanticAttributesHelper 87 | 88 | 89 | 90 | Classes: Railtie, SemanticAttributesBuilder 91 | 92 | 93 |
94 | 95 |"0.4.2"
77 |
78 |
79 |
|
129 |
Attrtastic is simple view helper which can be used to create index/show pages 60 | for any objects (for example Active Model objects). It helps you display 61 | all present attributes of object.
62 | 63 |If you need compatibility with Rails 2.x, then please install version 0.2.2 of 64 | this gem.
65 | 66 |Install the gem:
69 | 70 |gem install attrtastic 71 |72 | 73 |
Add to your Gemfile:
gem "attrtastic" 76 |77 | 78 |
And use in your views, for example in user/show.erb
79 | 80 |<%= semantic_attributes_for @user do |attr| %> 81 | <%= attr.attributes "User" do %> 82 | <%= attr.attribute :first_name %> 83 | <%= attr.attribute :last_name %> 84 | <%= attr.attribute :avatar do %> 85 | <%= image_tag @user.avatar.url %> 86 | <% end %> 87 | <% end %> 88 | <%= attr.attributes "Contact" do %> 89 | <%= attr.attribute :email %> 90 | <%= attr.attribute :tel %> 91 | <%= attr.attribute :fax %> 92 | <% end %> 93 | <% end %> 94 |95 | 96 |
By default attributes which returns #blank? value are ommited, unless
97 | :display_empty => true is added to #attribute.
Copyright (c) 2009-2011 Boruta Mirosław. See LICENSE for details.
Attrtastic is simple view helper which can be used to create index/show pages 60 | for any objects (for example Active Model objects). It helps you display 61 | all present attributes of object.
62 | 63 |If you need compatibility with Rails 2.x, then please install version 0.2.2 of 64 | this gem.
65 | 66 |Install the gem:
69 | 70 |gem install attrtastic 71 |72 | 73 |
Add to your Gemfile:
gem "attrtastic" 76 |77 | 78 |
And use in your views, for example in user/show.erb
79 | 80 |<%= semantic_attributes_for @user do |attr| %> 81 | <%= attr.attributes "User" do %> 82 | <%= attr.attribute :first_name %> 83 | <%= attr.attribute :last_name %> 84 | <%= attr.attribute :avatar do %> 85 | <%= image_tag @user.avatar.url %> 86 | <% end %> 87 | <% end %> 88 | <%= attr.attributes "Contact" do %> 89 | <%= attr.attribute :email %> 90 | <%= attr.attribute :tel %> 91 | <%= attr.attribute :fax %> 92 | <% end %> 93 | <% end %> 94 |95 | 96 |
By default attributes which returns #blank? value are ommited, unless
97 | :display_empty => true is added to #attribute.
Copyright (c) 2009-2011 Boruta Mirosław. See LICENSE for details.
83 | Helper which should be included in ActionView. Adds 84 | #semantic_attributes_for method, which helps printing attributes for given 85 | record, similar to formtastic’s sematnic_form_for 86 |
87 | 88 | 89 |147 | Creates attributes for given object. 148 |
149 |165 | 166 | - (Object) semantic_attributes_for(record, options = {}) {|attr| ... } 167 | 168 | 169 | 170 |
173 | Creates attributes for given object 174 |
175 |176 | @param[ActiveRecord] record AR instance record for which to display 177 | attributes @param[Hash] options Opions 178 |
179 | 180 | 181 |
293 | 294 | 295 | 296 | 44 297 | 45 298 | 46 299 | 47 300 | 48 301 | 49 302 | 50 303 | 51 304 | 52 305 | 53 306 | 54 307 | 55 308 | 56 309 | 57 310 | 58311 | |
312 |
313 | # File 'lib/attrtastic/semantic_attributes_helper.rb', line 44 314 | 315 | def semantic_attributes_for(record, = {}, &block) 316 | [:html] ||= {} 317 | 318 | html_class = [ "attrtastic", record.class.to_s.underscore, [:html][:class] ].compact.join(" ") 319 | 320 | output = tag(:div, { :class => html_class}, true) 321 | if block_given? 322 | output << capture(SemanticAttributesBuilder.new(record, self), &block) 323 | else 324 | output << capture(SemanticAttributesBuilder.new(record, self)) do |attr| 325 | attr.attributes 326 | end 327 | end 328 | output.safe_concat("</div>") 329 | end330 | |
331 |
122 | Only for testing purposes. 123 |
124 |149 | Only for testing purposes. 150 |
151 |186 | Creates list entry for single record attribute. 187 |
188 |210 | Creates block of attributes with optional header. 211 |
212 |236 | A new instance of SemanticAttributesBuilder. 237 |
238 |251 | 252 | - (SemanticAttributesBuilder) initialize(record, template) 253 | 254 | 255 | 256 |
259 | A new instance of SemanticAttributesBuilder 260 |
261 | 262 | 263 |
270 | 271 | 272 | 273 | 12 274 | 13 275 | 14276 | |
277 |
278 | # File 'lib/attrtastic/semantic_attributes_builder.rb', line 12 279 | 280 | def initialize(record, template) 281 | @record, @template = record, template 282 | end283 | |
284 |
298 | 299 | - (Object) record (readonly) 300 | 301 | 302 | 303 | Also known as: 304 | object 305 | 306 | 307 |
310 | Only for testing purposes 311 |
312 | 313 | 314 |
321 | 322 | 323 | 324 | 7 325 | 8 326 | 9327 | |
328 |
329 | # File 'lib/attrtastic/semantic_attributes_builder.rb', line 7 330 | 331 | def record 332 | @record 333 | end334 | |
335 |
344 | 345 | - (Object) template (readonly) 346 | 347 | 348 | 349 |
352 | Only for testing purposes 353 |
354 | 355 | 356 |
363 | 364 | 365 | 366 | 7 367 | 8 368 | 9369 | |
370 |
371 | # File 'lib/attrtastic/semantic_attributes_builder.rb', line 7 372 | 373 | def template 374 | @template 375 | end376 | |
377 |
390 | 391 | 392 | - (Object) attribute(method, options = {}) 393 | 394 | - (Object) attribute(method, options = {}) { ... } 395 | 396 | - (Object) attribute(options = {}) { ... } 397 | 398 | 399 | 400 | 401 |
404 | Creates list entry for single record attribute 405 |
406 | 407 | 408 |
822 | 823 | 824 | 825 | 280 826 | 281 827 | 282 828 | 283 829 | 284 830 | 285 831 | 286 832 | 287 833 | 288 834 | 289 835 | 290 836 | 291 837 | 292 838 | 293 839 | 294 840 | 295 841 | 296 842 | 297 843 | 298 844 | 299 845 | 300 846 | 301 847 | 302 848 | 303 849 | 304 850 | 305 851 | 306 852 | 307 853 | 308 854 | 309 855 | 310 856 | 311 857 | 312 858 | 313 859 | 314 860 | 315 861 | 316 862 | 317 863 | 318 864 | 319 865 | 320 866 | 321 867 | 322 868 | 323 869 | 324 870 | 325 871 | 326 872 | 327 873 | 328 874 | 329 875 | 330 876 | 331 877 | 332 878 | 333879 | |
880 |
881 | # File 'lib/attrtastic/semantic_attributes_builder.rb', line 280 882 | 883 | def attribute(*args, &block) 884 | = args. 885 | [:html] ||= {} 886 | 887 | method = args.shift 888 | 889 | html_label_class = [ "label", [:html][:label_class] ].compact.join(" ") 890 | html_value_class = [ "value", [:html][:value_class] ].compact.join(" ") 891 | html_class = [ "attribute", [:html][:class] ].compact.join(" ") 892 | 893 | label = .key?(:label) ? [:label] : label_for_attribute(method) 894 | 895 | unless block_given? 896 | value = if .key?(:value) 897 | case [:value] 898 | when Symbol 899 | attribute_value = value_of_attribute(method) 900 | case attribute_value 901 | when Hash 902 | attribute_value[[:value]] 903 | else 904 | attribute_value.send([:value]) 905 | end 906 | else 907 | [:value] 908 | end 909 | else 910 | value_of_attribute(method) 911 | end 912 | 913 | value = case [:format] 914 | when false 915 | value 916 | when nil 917 | format_attribute_value(value) 918 | else 919 | template.send([:format], value) 920 | end 921 | 922 | if value.present? or [:display_empty] 923 | output = template.tag(:li, {:class => html_class}, true) 924 | output << template.content_tag(:span, label, :class => html_label_class) 925 | output << template.content_tag(:span, value, :class => html_value_class) 926 | output.safe_concat("</li>") 927 | end 928 | else 929 | output = template.tag(:li, {:class => html_class}, true) 930 | output << template.content_tag(:span, label, :class => html_label_class) 931 | output << template.tag(:span, {:class => html_value_class}, true) 932 | output << template.capture(&block) 933 | output.safe_concat("</span>") 934 | output.safe_concat("</li>") 935 | end 936 | end937 | |
938 |
944 | 945 | 946 | - (Object) attributes(options = {}) { ... } 947 | 948 | - (Object) attributes(header, options = {}) {|builder| ... } 949 | 950 | - (Object) attributes(*symbols, options = {}) 951 | 952 | - (Object) attributes(header, *symbols, options = {}) 953 | 954 | 955 | 956 | 957 |
960 | Creates block of attributes with optional header. Attributes are surrounded 961 | with ordered list. 962 |
963 | 964 | 965 |
1619 | 1620 | 1621 | 1622 | 187 1623 | 188 1624 | 189 1625 | 190 1626 | 191 1627 | 192 1628 | 193 1629 | 194 1630 | 195 1631 | 196 1632 | 197 1633 | 198 1634 | 199 1635 | 200 1636 | 201 1637 | 202 1638 | 203 1639 | 204 1640 | 205 1641 | 206 1642 | 207 1643 | 208 1644 | 209 1645 | 210 1646 | 211 1647 | 2121648 | |
1649 |
1650 | # File 'lib/attrtastic/semantic_attributes_builder.rb', line 187 1651 | 1652 | def attributes(*args, &block) 1653 | = args. 1654 | [:html] ||= {} 1655 | 1656 | if args.first and args.first.is_a? String 1657 | [:name] = args.shift 1658 | end 1659 | 1660 | if [:for].blank? 1661 | attributes_for(record, args, , &block) 1662 | else 1663 | for_value = if [:for].is_a? Symbol 1664 | record.send([:for]) 1665 | else 1666 | [:for] 1667 | end 1668 | 1669 | [*for_value].map do |value| 1670 | = .clone 1671 | [:html][:class] = [ [:html][:class], value.class.to_s.underscore ].compact.join(" ") 1672 | 1673 | attributes_for(value, args, , &block) 1674 | end.join.html_safe 1675 | end 1676 | 1677 | end1678 | |
1679 |