inherited_rails_views 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
- .idea/
5
+ .idea/
6
+ .DS_Store
data/Readme.md CHANGED
@@ -25,4 +25,19 @@ Add the inherited_rails_views gem to your Applications Gemfile:
25
25
  You can also override any of the files in [https://github
26
26
  .com/rweng/inherited_rails_views/tree/master/lib/inherited_rails_views/views/application][viewsdir].
27
27
 
28
- [viewsdir]:https://github.com/rweng/inherited_rails_views/tree/master/lib/inherited_rails_views/views/application
28
+ [viewsdir]:https://github.com/rweng/inherited_rails_views/tree/master/lib/inherited_rails_views/views/application
29
+
30
+ # Internationalization
31
+
32
+ Inherited Rails Views provides provides and uses the method irv_t for translations. irv_t takes a lazy lookup string
33
+ and tries to look up the translation over different paths. Example:
34
+
35
+ # called from /countries/index
36
+ irv_t "actions.show", :default => "Show This", :bla => 1
37
+ # tries looking up in the following order:
38
+ # countries.index.actions.show
39
+ # countries.actions.show
40
+ # application.index.actions.show
41
+ # application.actions.show
42
+
43
+ If none of translation keys are set, `"Show This"` is displayed. The variable `bla` is passed in the localization value.
@@ -0,0 +1,3 @@
1
+ module InheritedRailsViewsHelper
2
+
3
+ end
@@ -6,7 +6,6 @@ require 'active_support/core_ext/module'
6
6
 
7
7
  require 'active_support/concern'
8
8
 
9
-
10
9
  # sets the attributes to be displayed by inherited_rails_views
11
10
  #
12
11
  # inherited_attributes :method1, :method2, :method3
@@ -22,15 +21,33 @@ require 'active_support/concern'
22
21
  #
23
22
  module InheritedRailsViews
24
23
  extend ActiveSupport::Concern
24
+ I18n.load_path += Dir.glob(File.dirname(__FILE__) + "/locales/*.yml")
25
25
 
26
26
  included do
27
- append_view_path(File.expand_path "../inherited_rails_views/views", __FILE__)
28
-
29
- helper_method :inherited_attributes
27
+ append_view_path(File.expand_path "../views", __FILE__)
28
+ # helper ... doesn't work: uninitialized constant Users error
29
+ helper_method :inherited_attributes, :irv_t
30
30
  end
31
31
 
32
32
 
33
33
  module InstanceMethods
34
+ # would like to have this in a helper, which doesn't work
35
+ def irv_t lazy, options = {}
36
+ options[:default] = [
37
+ :"#{params[:controller]}.#{lazy}",
38
+ :"application.#{params[:action]}.#{lazy}",
39
+ :"application.#{lazy}"
40
+ ] + [*options[:default]]
41
+
42
+ options.reverse_merge!({
43
+ :resource => resource_class.model_name.human,
44
+ :action => params[:action],
45
+ :controller => params[:controller]
46
+ })
47
+
48
+ I18n.t("#{params[:controller]}.#{params[:action]}.#{lazy}", options)
49
+ end
50
+
34
51
  def inherited_attributes(*args)
35
52
  if args.empty?
36
53
  @_inherited_attributes || _default_inherited_attributes
@@ -42,7 +59,7 @@ module InheritedRailsViews
42
59
  private
43
60
  def _set_inherited_attributes(*args)
44
61
 
45
-
62
+
46
63
  # extract the hash attributes
47
64
  options = args.extract_options!
48
65
 
@@ -57,7 +74,7 @@ module InheritedRailsViews
57
74
  @_inherited_attributes.keys.each do |k|
58
75
  v = @_inherited_attributes[k]
59
76
  v = {} if v == true
60
- v[:value] = k.to_s.titleize if !v.has_key?(:value) or v[:value] == true
77
+ v[:value] = resource_class.human_attribute_name(k) if !v.has_key?(:value) or v[:value] == true
61
78
  v[:type] ||= :text_field
62
79
  @_inherited_attributes[k] = v
63
80
  end
@@ -1,3 +1,3 @@
1
1
  module InheritedRailsViews
2
- VERSION = "1.1.4"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,21 @@
1
+ de:
2
+ application:
3
+ new:
4
+ heading: "Neue %{resource}"
5
+ index:
6
+ heading: "%{resource}"
7
+ edit:
8
+ heading: "%{resource} bearbeiten"
9
+ actions:
10
+ show: Anzeigen
11
+ edit: Bearbeiten
12
+ destroy: Löschen
13
+ destroy_confirmation: Sind Sie sicher, dass Sie das Objekt löschen wollen?
14
+ new: Neue %{resource}
15
+ back: Zurück
16
+ save:
17
+ new: "%{resource} erstellen"
18
+ edit: "%{resource} aktuallisieren"
19
+ errors_msg:
20
+ one: "Ein Fehler verhinderte das speichern des Objekts:"
21
+ other: "%{count} Fehler verhinderten das speichern des Objekts:"
@@ -8,7 +8,7 @@
8
8
  <tr>
9
9
  <td></td>
10
10
  <td class="actions">
11
- <%= f.submit "Save" %>
11
+ <%= f.submit irv_t( "actions.save.#{ params[:action] }", :default => "Save") %>
12
12
  </td>
13
13
  </tr>
14
14
  </table>
@@ -1,7 +1,7 @@
1
1
  <%= form_for resource do |f| %>
2
2
  <% if resource.errors.any? %>
3
3
  <div id="error_explanation">
4
- <h2><%= "#{pluralize(resource.errors.count, "error")} prohibited this news from being saved:" %></h2>
4
+ <h2><%= irv_t "errors_msg", :count => resource.errors.count, :default => "#{pluralize(resource.errors.count, "error")} prohibited this news from being saved:" %></h2>
5
5
  <ul>
6
6
  <% resource.errors.full_messages.each do |msg| %>
7
7
  <li><%= msg %></li>
@@ -0,0 +1,7 @@
1
+ <h1><%= irv_t "heading", :default => "Editing #{resource_class.to_s.titleize}" %></h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to irv_t("actions.show", :defaults => "Show"), resource_path %>
6
+ |
7
+ <%= link_to (irv_t "actions.back", :default => 'Back'), collection_path %>
@@ -0,0 +1,28 @@
1
+ <h1>
2
+ <%= irv_t("heading", :default => "Listing #{resource_class.model_name.human}", :resource => resource_class.model_name.human ) %>
3
+ </h1>
4
+
5
+ <table>
6
+ <tr>
7
+ <% inherited_attributes.each_pair do |k, v| %>
8
+ <th><%= v[:value] %></th>
9
+ <% end %>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% collection.each do |res| %>
14
+ <tr>
15
+ <% inherited_attributes.each_pair do |k, v| %>
16
+ <td><%= res.send(k) %></td>
17
+ <% end %>
18
+ <td><%= link_to irv_t("actions.show", :default => "Show"), res %> </td>
19
+ <td><%= link_to irv_t("actions.edit", :default => "Edit"), edit_resource_path(res) %> </td>
20
+ <td><%= link_to irv_t("actions.destroy", :default => "Delete"), res,
21
+ :confirm => irv_t('actions.destroy_confirmation', :default => "Are you sure you want to destroy this?"),
22
+ :method => :delete %></td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+
27
+ <br/>
28
+ <%= link_to irv_t('actions.new', :resource => resource_class.model_name.human, :default => "New #{resource_class.model_name.human}"), new_resource_path %>
@@ -0,0 +1,8 @@
1
+ <h1>
2
+ <%= irv_t "heading", :default =>"New #{resource_class.to_s.titleize}" %>
3
+ </h1>
4
+
5
+ <%= render 'form' %>
6
+
7
+ <%= link_to (irv_t "actions.back", :default => 'Back'), collection_path %>
8
+
@@ -0,0 +1,18 @@
1
+ <h1><%= irv_t("heading", :default => resource_class.model_name.human) %></h1>
2
+
3
+ <table>
4
+ <% inherited_attributes.each_pair do |k,v| %>
5
+ <tr>
6
+ <td>
7
+ <b>
8
+ <%= v[:value] %></b>
9
+ <td>
10
+ <%= resource.send k %></td>
11
+ </tr>
12
+ <% end %>
13
+ </table>
14
+
15
+ <br />
16
+ <%= link_to (irv_t "actions.edit", :default => 'Edit'), edit_resource_path(resource) %>
17
+ |
18
+ <%= link_to (irv_t 'actions.back', :default => 'Back'), collection_path %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inherited_rails_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-20 00:00:00.000000000Z
12
+ date: 2011-09-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70222799214300 !ruby/object:Gem::Requirement
16
+ requirement: &70325744543520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70222799214300
24
+ version_requirements: *70325744543520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70222799213280 !ruby/object:Gem::Requirement
27
+ requirement: &70325744542920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70222799213280
35
+ version_requirements: *70325744542920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: actionpack
38
- requirement: &70222799212200 !ruby/object:Gem::Requirement
38
+ requirement: &70325744542240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70222799212200
46
+ version_requirements: *70325744542240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70222799211180 !ruby/object:Gem::Requirement
49
+ requirement: &70325744541640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70222799211180
57
+ version_requirements: *70325744541640
58
58
  description:
59
59
  email:
60
60
  - robin@wenglewski.de
@@ -68,14 +68,16 @@ files:
68
68
  - Rakefile
69
69
  - Readme.md
70
70
  - inherited_rails_views.gemspec
71
+ - lib/helpers/inherited_rails_views_helper.rb
71
72
  - lib/inherited_rails_views.rb
72
73
  - lib/inherited_rails_views/version.rb
73
- - lib/inherited_rails_views/views/application/_fields.html.erb
74
- - lib/inherited_rails_views/views/application/_form.html.erb
75
- - lib/inherited_rails_views/views/application/edit.html.erb
76
- - lib/inherited_rails_views/views/application/index.html.erb
77
- - lib/inherited_rails_views/views/application/new.html.erb
78
- - lib/inherited_rails_views/views/application/show.html.erb
74
+ - lib/locales/de.yml
75
+ - lib/views/application/_fields.html.erb
76
+ - lib/views/application/_form.html.erb
77
+ - lib/views/application/edit.html.erb
78
+ - lib/views/application/index.html.erb
79
+ - lib/views/application/new.html.erb
80
+ - lib/views/application/show.html.erb
79
81
  - spec/inherited_rails_views_spec.rb
80
82
  homepage: https://github.com/rweng/inherited_rails_views
81
83
  licenses: []
@@ -1,7 +0,0 @@
1
- <h1>Editing <%= resource.class.to_s.titleize %></h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Show', resource %>
6
- |
7
- <%= link_to 'Back', collection_path %>
@@ -1,30 +0,0 @@
1
- <h1>
2
- Listing
3
- <%= collection.name %>
4
- </h1>
5
-
6
- <table>
7
- <tr>
8
- <% inherited_attributes.each_pair do |k, v| %>
9
- <th><%= v[:value] %></th>
10
- <% end %>
11
- <th></th>
12
- <th></th>
13
- <th></th>
14
- </tr>
15
-
16
- <% collection.each do |res| %>
17
- <tr>
18
- <% inherited_attributes.each_pair do |k, v| %>
19
- <td><%= res.send(k) %></td>
20
- <% end %>
21
- <td><%= link_to 'Show', res %> </td>
22
- <td><%= link_to 'Edit', edit_resource_path(res) %> </td>
23
- <td><%= link_to 'Destroy', res, :confirm => 'Are you sure?', :method => :delete %> </td>
24
- </tr>
25
- <% end %>
26
- </table>
27
-
28
- <br/>
29
- <%= link_to "Create #{collection.name}", new_resource_path %>
30
-
@@ -1,9 +0,0 @@
1
- <h1>
2
- New
3
- <%= resource.class.to_s.titleize %>
4
- </h1>
5
-
6
- <%= render 'form' %>
7
-
8
- <%= link_to 'Back', collection_path %>
9
-
@@ -1,16 +0,0 @@
1
- <p id="notice"><%= notice %></p>
2
-
3
- <table>
4
- <% inherited_attributes.each_pair do |k,v| %>
5
- <tr>
6
- <td>
7
- <b>
8
- <%= v[:value] %></b>
9
- <td>
10
- <%= resource.send k %></td>
11
- </tr>
12
- <% end %>
13
- </table>
14
- <%= link_to 'Edit', edit_resource_path(resource) %>
15
- |
16
- <%= link_to 'Back', collection_path %>