hobo 1.3.0.pre10 → 1.3.0.pre11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0.pre10
1
+ 1.3.0.pre11
@@ -31,13 +31,5 @@ module Hobo
31
31
  remove_file 'config/locales/en.yml'
32
32
  end
33
33
 
34
- def add_default_count_helper
35
- return if File.read('app/helpers/application_helper.rb') =~ /def default_count\b/
36
- inject_into_file 'app/helpers/application_helper.rb',
37
- File.read( File.expand_path('../templates/default_count_injection.rb', __FILE__)),
38
- :after => "module ApplicationHelper\n"
39
- end
40
-
41
-
42
34
  end
43
35
  end
@@ -75,18 +75,13 @@ module Hobo
75
75
  end
76
76
  # add :"hobo.#{key}" as the first fallback
77
77
  options[:default].unshift("hobo.#{subkey}".to_sym)
78
- # set the count option in order to allow multiple pluralization
79
- count = options.delete(:count)
80
- count = default_count if count.blank?
81
- c = count.try.to_i || count==:dynamic && klass.try.count
82
78
  # translate the model
83
79
  # the singularize method is used because Hobo does not keep the ActiveRecord convention in its tags
84
80
  # no default needed because human_name defaults to the model name
85
81
  # try because Hobo class is not an ActiveRecord::Base subclass
86
- translated_pluralized_model = klass.try.model_name.try.human(:count=>c)
82
+ translated_pluralized_model = klass.try.model_name.try.human(:count=>options[:count])
87
83
  options[:model] = translated_pluralized_model
88
84
  end
89
- options[:count] = c
90
85
 
91
86
  key_prefix = "<span class='translation-key'>#{key}</span>" if defined?(HOBO_SHOW_LOCALE_KEYS) && HOBO_SHOW_LOCALE_KEYS
92
87
 
@@ -4,7 +4,7 @@
4
4
  <navigation class="main-nav" merge-attrs param="default">
5
5
  <nav-item href="#{base_url}/">Home</nav-item>
6
6
  <% models.select { |m| linkable?(m, :index) }[0..4].each do |m| -%>
7
- <nav-item with="&<%= m.name %>"><ht key="<%= m.name.tableize %>.nav_item"><model-name-human/></ht></nav-item>
7
+ <nav-item with="&<%= m.name %>"><ht key="<%= m.name.tableize %>.nav_item" count="100"><model-name-human count="100"/></ht></nav-item>
8
8
  <% end -%>
9
9
  </navigation>
10
10
  </def>
@@ -21,7 +21,7 @@ model_key = model.name.tableize
21
21
  -%>
22
22
 
23
23
  <def tag="index-page" for="<%= model.name %>">
24
- <page merge title="#{ht '<%= model_key %>.index.title', :default=>[model.model_name.human(:count=>model.count)] }">
24
+ <page merge title="#{ht '<%= model_key %>.index.title', :default=>[model.model_name.human(:count=>100)] }">
25
25
  <body: class="index-page <%= model_class %>" param/>
26
26
 
27
27
  <content: param>
@@ -283,7 +283,7 @@ new_link = :new.in?(actions)
283
283
  -%>
284
284
  <def tag="index-for-<%= owner.dasherize %>-page" polymorphic/>
285
285
  <def tag="index-for-<%= owner.dasherize %>-page" for="<%= model.name %>">
286
- <page merge title="#{ht '<%= model_key %>.index_for_owner.title', :default=>['<%= sq_escape(model_name(:plural)) %> for']} #{name :with => @<%= owner %>, :no_wrapper => true}">
286
+ <page merge title="#{ht '<%= model_key %>.index_for_owner.title', :count=>100, :default=>['<%= sq_escape(model_name(:plural)) %> for']} #{name :with => @<%= owner %>, :no_wrapper => true}">
287
287
  <body: class="index-for-owner-page <%= owner.dasherize %> <%= model_class %>" param/>
288
288
  <content: param>
289
289
  <header param="content-header">
@@ -12,7 +12,7 @@ There is a default :count => 1
12
12
  -->
13
13
  <def tag="t"><%=
14
14
  options = {}
15
- attributes.each_pair{|k,v| options[k.to_sym] = h(v)}
15
+ all_attributes.each_pair{|k,v| options[k.to_sym] = h(v)}
16
16
  k = options.delete(:key)
17
17
  I18n.t(k, {:default=>all_parameters.default}.merge(options)).html_safe
18
18
  %></def>
@@ -23,21 +23,16 @@ It dynamically pluralizes the human name by using the implicit model.count.
23
23
  #### Attributes
24
24
 
25
25
  - model - (optional) should be a model class or a record object (default to this)
26
- - count - (optional) used to pick the inflected string for the model. It should be an integer
27
- or the symbol :dynamic if you want to have the pluralization consistent with the model.count.
28
- If you don't pass any count it uses the ApplicationHelper#default_count.
26
+ - count - (optional) used to pick the inflected string for the model. It should be an integer.
29
27
  -->
30
28
 
31
29
  <def tag="model-name-human" attrs="model, count"><%=
32
30
  model ||= this
33
31
  model = model.class unless model.kind_of? Class
34
- # adapted from count tag
35
- count = default_count if count.blank?
36
- c = count.try.to_int || count==:dynamic && this.try.total_entries || (this.try.loaded? && this.try.length) || this.try.count || this.try.length
37
32
  # prepare symbolized attributes for merging
38
33
  attrs = {}
39
- attributes.each_pair{|k,v| attrs[k.to_sym] = v}
40
- model.model_name.human( {:count=>c}.merge(attrs) )
34
+ all_attributes.each_pair{|k,v| attrs[k.to_sym] = v}
35
+ model.model_name.human( attrs )
41
36
  %>
42
37
  </def>
43
38
 
@@ -57,21 +52,20 @@ It dynamically pluralizes the human name by using the implicit model.count.
57
52
  model = model.class unless model.kind_of? Class
58
53
  # prepare symbolized attributes for merging
59
54
  attrs = {}
60
- attributes.each_pair{|k,v| attrs[k.to_sym] = v}
55
+ all_attributes.each_pair{|k,v| attrs[k.to_sym] = v}
61
56
  model.human_attribute_name( attribute.to_sym, attrs )
62
57
  %>
63
58
  </def>
64
59
 
65
60
  <!-- Used to localize and pluralize collection names.
66
- A collection name is a special case of an attribute name, (indeed you should store the collection names as attribute names in the locale files), so this tag internally uses human_attribute_name to return them. It does also the default pluralization by calling count on the collection attribute (that you can override passing an explicit `count` attribute).
61
+ A collection name is a special case of an attribute name, (indeed you should store the collection names as attribute names in the locale files), so this tag internally uses human_attribute_name to return them.
67
62
 
68
63
  With the `your` attribute and in the special case the context is a Hobo::Model::User instance it automatically embeds the `your` tag funtionality. (note: :name is added by default as an interpolable variable)
69
64
 
70
65
  ### Attributes
71
66
 
72
67
  - collection - the attribute/collection key to lookup in the `activerecord.attributes` namespace. (e.g. 'roles')
73
- - count - It should be an integer or the symbol :dynamic if you want to have the pluralization
74
- consistent with the collection.count. If you don't pass any count it uses the ApplicationHelper#default_count.
68
+ - count - used to pick the inflected string for the collection. It should be an integer.
75
69
  - your - wraps the collection name in a `Your` tag
76
70
 
77
71
  ### Example
@@ -99,17 +93,17 @@ With the `your` attribute and in the special case the context is a Hobo::Model::
99
93
  other: Ruoli di {{name}}"
100
94
 
101
95
  # context is a Post instance ('your' is ignored)
102
- <human-collection-name collection="comments" your/>
96
+ <human-collection-name collection="comments" count="&user.comments.count" your/>
103
97
  I18n.locale = :en => "Comment" or "Comments"
104
98
  I18n.locale = :it => "Commento" or "Commenti"
105
99
 
106
100
  # context is an User instance
107
- <human-collection-name collection="roles' your/>
101
+ <human-collection-name collection="roles' count="&user.roles.count" your/>
108
102
  I18n.locale = :en => "Your Role" or "Jim's Role" or "Your Roles" or "Jim's Roles"
109
103
  I18n.locale = :it => "Il tuo Ruolo" or "Il Ruolo di Jim" or "I tuoi Ruoli" or "I Ruoli di Jim"
110
104
  (output is the same as <Your key="roles" count=>"&user.roles.count"/> )
111
105
 
112
- <human-collection-name collection="roles"/>
106
+ <human-collection-name collection="roles" count="&user.roles.count"/>
113
107
  I18n.locale = :en => "Role" or "Roles"
114
108
  I18n.locale = :it => "Ruolo" or "Ruoli"
115
109
  -->
@@ -117,17 +111,15 @@ With the `your` attribute and in the special case the context is a Hobo::Model::
117
111
  raise Hobo::Error, "The 'collection' attribute must be defined" if collection.blank?
118
112
  belong_class = this.kind_of?(Class) ? this : this.class
119
113
  raise Hobo::Error, "The context is not an ActiveRecord::Base instance or class. (this = #{this.typed_id rescue this.inspect})" unless belong_class < ActiveRecord::Base
120
- count = default_count if count.blank?
121
- c = count.try.to_int || count==:dynamic && this.kind_of?(ActiveRecord::Base) && this.send(collection.to_sym).count
122
114
  # prepare symbolized attributes for merging
123
115
  attrs = {}
124
- attributes.each_pair{|k,v| attrs[k.to_sym] = v} -%>
116
+ all_attributes.each_pair{|k,v| attrs[k.to_sym] = v} -%>
125
117
  <% if your && belong_class < Hobo::Model::User && this.kind_of?(Hobo::Model::User) && I18n.locale == :en -%>
126
118
  <your key="&collection" merge-attrs="&{:count=>c, :name=>this.name}.merge(attrs)" capitalize>
127
- <%= belong_class.human_attribute_name(collection.to_sym, {:count=>c}.merge(attrs)) %>
119
+ <%= belong_class.human_attribute_name(collection.to_sym, attrs) %>
128
120
  </your>
129
121
  <% else -%>
130
- <%= belong_class.human_attribute_name( collection.to_sym, {:count=>c}.merge(attrs) ) %>
122
+ <%= belong_class.human_attribute_name( collection.to_sym, attrs ) %>
131
123
  <% end %>
132
124
  </def>
133
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobo
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1637175975
4
+ hash: -1637175962
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
9
  - 0
10
- - pre10
11
- version: 1.3.0.pre10
10
+ - pre11
11
+ version: 1.3.0.pre11
12
12
  platform: ruby
13
13
  authors:
14
14
  - Tom Locke
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-10 00:00:00 -04:00
19
+ date: 2010-10-11 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -59,13 +59,13 @@ dependencies:
59
59
  requirements:
60
60
  - - "="
61
61
  - !ruby/object:Gem::Version
62
- hash: -1637175975
62
+ hash: -1637175962
63
63
  segments:
64
64
  - 1
65
65
  - 3
66
66
  - 0
67
- - pre10
68
- version: 1.3.0.pre10
67
+ - pre11
68
+ version: 1.3.0.pre11
69
69
  type: :runtime
70
70
  version_requirements: *id003
71
71
  - !ruby/object:Gem::Dependency
@@ -76,13 +76,13 @@ dependencies:
76
76
  requirements:
77
77
  - - "="
78
78
  - !ruby/object:Gem::Version
79
- hash: -1637175975
79
+ hash: -1637175962
80
80
  segments:
81
81
  - 1
82
82
  - 3
83
83
  - 0
84
- - pre10
85
- version: 1.3.0.pre10
84
+ - pre11
85
+ version: 1.3.0.pre11
86
86
  type: :runtime
87
87
  version_requirements: *id004
88
88
  - !ruby/object:Gem::Dependency
@@ -93,13 +93,13 @@ dependencies:
93
93
  requirements:
94
94
  - - "="
95
95
  - !ruby/object:Gem::Version
96
- hash: -1637175975
96
+ hash: -1637175962
97
97
  segments:
98
98
  - 1
99
99
  - 3
100
100
  - 0
101
- - pre10
102
- version: 1.3.0.pre10
101
+ - pre11
102
+ version: 1.3.0.pre11
103
103
  type: :runtime
104
104
  version_requirements: *id005
105
105
  - !ruby/object:Gem::Dependency
@@ -199,7 +199,6 @@ files:
199
199
  - lib/generators/hobo/i18n/templates/app.es-DO.yml
200
200
  - lib/generators/hobo/i18n/templates/app.it.yml
201
201
  - lib/generators/hobo/i18n/templates/app.pt-PT.yml
202
- - lib/generators/hobo/i18n/templates/default_count_injection.rb
203
202
  - lib/generators/hobo/i18n/templates/hobo.en.yml
204
203
  - lib/generators/hobo/i18n/templates/hobo.es-DO.yml
205
204
  - lib/generators/hobo/i18n/templates/hobo.it.yml
@@ -1,10 +0,0 @@
1
-
2
- # the default_count is called from i18n tags in order to produce the right pluralization
3
- # when no count is explicitly passed. It is normally used to generate a plural.
4
- # You can return different integers according to the needs of different languages
5
- # if you return the symbol :dynamic the count will be the model count
6
- # so the tag output will be singular or plural depending on the record count
7
- def default_count
8
- 100 # fixed plural by default
9
- end
10
-