mappable 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -46,6 +46,10 @@ You can use the included generator to copy the views if you'd like to customize
46
46
 
47
47
  rails generate mappable:views
48
48
 
49
+ If you want to override the views for `mappings` that belong to a specific `map` puts them in `app/views/mappable/[MAP_NAME]/mappings`. You can also generate these scoped views:
50
+
51
+ rails generate mappable:views account_names
52
+
49
53
  Definitions
50
54
 
51
55
  * **Mappings**: String pairs that map to each other
@@ -84,6 +88,5 @@ Now you can map strings in either direction using the following grammar
84
88
 
85
89
  Move rebuilding of maps to an initializer and/or add notes to readme about why Map.all gets called on every request in development
86
90
  Better indexing in migrations
87
- Rake task for installing views
88
91
  Add security features
89
92
  Deal with going from/to when there's more than one to with the same name
@@ -1,6 +1,7 @@
1
1
  module Mappable
2
2
  class MappingsController < ::ApplicationController
3
- before_filter :load_map!, only: [:index, :new]
3
+ before_filter :load_map_attributes
4
+ before_filter :load_map, only: [:index, :new]
4
5
 
5
6
  def index
6
7
  @mappings = @map.mappings
@@ -47,8 +48,28 @@ module Mappable
47
48
 
48
49
  private
49
50
 
50
- def load_map!
51
- @map = Map.find_by_subject_and_attr!(params[:subject], params[:attr].try(:singularize))
52
- end
51
+ def load_map
52
+ @map = Map.find_by_subject_and_attr!(params[:subject], params[:attr].singularize)
53
+ end
54
+
55
+ def load_map_attributes
56
+ @subject = params[:subject]
57
+ @attr = params[:attr].singularize
58
+ end
59
+
60
+ def render(*args, &block)
61
+ options = _normalize_render(*args, &block)
62
+ options[:prefixes].unshift map_specific_view_path
63
+ self.response_body = render_to_body(options)
64
+ end
65
+
66
+ def map_specific_view_path
67
+ "mappable/#{@subject}_#{@attr.pluralize}/#{engine_controller}"
68
+ end
69
+
70
+ def engine_controller
71
+ params[:controller].split("/").last
72
+ end
73
+
53
74
  end
54
75
  end
@@ -12,16 +12,20 @@
12
12
  <% end %>
13
13
 
14
14
  <div class="field">
15
- <%= f.label :from %><br />
15
+ <%= f.label :from, "#{@mapping.map.from.humanize} #{@mapping.map.subject.humanize.downcase} #{@mapping.map.attr.humanize.downcase}" %><br />
16
16
  <%= f.text_field :from %>
17
17
  </div>
18
+
18
19
  <div class="field">
19
- <%= f.label :to %><br />
20
+ <%= f.label :to, "#{@mapping.map.to.humanize} #{@mapping.map.subject.humanize.downcase} #{@mapping.map.attr.humanize.downcase}" %><br />
20
21
  <%= f.text_field :to %>
21
22
  </div>
23
+
22
24
  <%= f.hidden_field :map_id %>
25
+
23
26
  <div class="actions">
24
27
  <% label = @mapping.new_record? ? "Create Mapping" : "Update Mapping" %>
25
28
  <%= f.submit label %>
26
29
  </div>
30
+
27
31
  <% end %>
@@ -1,4 +1,4 @@
1
- <h1><%= @map.subject.humanize %> <%= @map.attr.humanize.downcase %> mappings</h1>
1
+ <h1><%= "#{@map.subject.humanize} #{@map.attr.humanize.downcase} mappings" %></h1>
2
2
 
3
3
  <table>
4
4
  <tr>
@@ -1,4 +1,4 @@
1
- <h1>New mapping</h1>
1
+ <h1><%= "New #{@mapping.parent_map.subject.humanize.titleize} #{@mapping.parent_map.attr.humanize.titleize} Mapping" %></h1>
2
2
 
3
3
  <%= render 'form' %>
4
4
 
@@ -1,17 +1,14 @@
1
- <h1>Edit <%= @mapping.map.subject.humanize.titleize %> <%= @mapping.map.attr.humanize.titleize %> Mappings</h1>
1
+ <h1><%= "#{@mapping.parent_map.subject.humanize.titleize} #{@mapping.parent_map.attr.humanize.titleize} Mapping" %></h1>
2
2
 
3
3
  <p>
4
- <b>Map:</b>
5
- <%= @mapping.parent_map.subject %>
6
- </p>
7
-
8
- <p>
9
- <b>From:</b>
4
+ <b><%= "#{@mapping.map.from.humanize} #{@mapping.parent_map.subject.humanize.downcase} #{@mapping.parent_map.attr.humanize.downcase}" %>:</b>
5
+ <br />
10
6
  <%= @mapping.from %>
11
7
  </p>
12
8
 
13
9
  <p>
14
- <b>To:</b>
10
+ <b><%= "#{@mapping.map.to.humanize} #{@mapping.parent_map.subject.humanize.downcase} #{@mapping.parent_map.attr.humanize.downcase}" %>:</b>
11
+ <br />
15
12
  <%= @mapping.to %>
16
13
  </p>
17
14
 
@@ -17,7 +17,7 @@
17
17
  <td><%= map.attr %></td>
18
18
  <td><%= map.from %></td>
19
19
  <td><%= map.to %></td>
20
- <td><%= link_to 'Show', mappings_path(subject: map.subject, attr: map.attr.pluralize) %></td>
20
+ <td><%= link_to 'Show', mappings_path(subject: map.subject, attr: map.attr) %></td>
21
21
  <td><%= link_to 'Edit', edit_map_path(map) %></td>
22
22
  <td><%= link_to 'Destroy', map, confirm: 'Are you sure?', method: :delete %></td>
23
23
  </tr>
@@ -1,4 +1,4 @@
1
- <h1><%= @map.subject.humanize.titleize %> <%= @map.attr.humanize.titleize %> Mappings</h1>
1
+ <h1><%= "#{@map.subject.humanize.titleize} #{@map.attr.humanize.titleize} Mappings" %></h1>
2
2
 
3
3
  <h2>Maps <em><%= @map.from %></em> to <em><%= @map.to %></em></h2>
4
4
 
@@ -18,3 +18,15 @@ Example:
18
18
  app/views/mappable/maps/index.html.erb
19
19
  app/views/mappable/maps/new.html.erb
20
20
  app/views/mappable/maps/show.html.erb
21
+
22
+ rails generate mappable:views account_names
23
+
24
+ This will create:
25
+ app/views/mappable
26
+ app/views/mappable/account_names
27
+ app/views/mappable/account_names/mappings
28
+ app/views/mappable/account_names/mappings/_form.html.erb
29
+ app/views/mappable/account_names/mappings/edit.html.erb
30
+ app/views/mappable/account_names/mappings/index.html.erb
31
+ app/views/mappable/account_names/mappings/new.html.erb
32
+ app/views/mappable/account_names/mappings/show.html.erb
@@ -1,20 +1,39 @@
1
1
  module Mappable
2
2
  class ViewsGenerator < Rails::Generators::NamedBase
3
3
  source_root File.expand_path('../../../../../app/views/mappable', __FILE__)
4
- argument :name, :type => :string, :default => 'views'
4
+ argument :name, :type => :string, :default => ''
5
5
 
6
6
  def copy_view_files
7
- empty_directory "app/views/mappable/maps"
8
- copy_file "maps/_form.html.erb", "app/views/mappable/maps/_form.html.erb"
9
- copy_file "maps/edit.html.erb", "app/views/mappable/maps/edit.html.erb"
10
- copy_file "maps/index.html.erb", "app/views/mappable/maps/index.html.erb"
11
- copy_file "maps/new.html.erb", "app/views/mappable/maps/new.html.erb"
12
- copy_file "maps/show.html.erb", "app/views/mappable/maps/show.html.erb"
13
- empty_directory "app/views/mappable/mappings"
14
- copy_file "mappings/edit.html.erb", "app/views/mappable/mappings/edit.html.erb"
15
- copy_file "mappings/index.html.erb", "app/views/mappable/mappings/index.html.erb"
16
- copy_file "mappings/new.html.erb", "app/views/mappable/mappings/new.html.erb"
17
- copy_file "mappings/show.html.erb", "app/views/mappable/mappings/show.html.erb"
7
+
8
+ map_files = %w[
9
+ maps/_form
10
+ maps/edit
11
+ maps/index
12
+ maps/new
13
+ maps/show
14
+ ]
15
+
16
+ mapping_files = %w[
17
+ mappings/_form
18
+ mappings/edit
19
+ mappings/index
20
+ mappings/new
21
+ mappings/show
22
+ ]
23
+
24
+ files = mapping_files
25
+ files += map_files if name.blank?
26
+
27
+ files.each do |file|
28
+ from_path = "#{file}.html.erb"
29
+
30
+ path_parts = ["mappable"]
31
+ path_parts.push(name) unless name.blank? # include the name as namespace if not blank
32
+ path_parts.push("#{file}.html.erb")
33
+
34
+ to_path = File.join('app/views', *path_parts)
35
+ copy_file from_path, to_path
36
+ end
18
37
  end
19
38
  end
20
39
  end
@@ -1,3 +1,3 @@
1
1
  module Mappable
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mappable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-30 00:00:00.000000000Z
12
+ date: 2011-10-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70188236597900 !ruby/object:Gem::Requirement
16
+ requirement: &70243809829940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70188236597900
24
+ version_requirements: *70243809829940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70188236597360 !ruby/object:Gem::Requirement
27
+ requirement: &70243809828860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.3.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70188236597360
35
+ version_requirements: *70243809828860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70188236596900 !ruby/object:Gem::Requirement
38
+ requirement: &70243809827540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.6.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70188236596900
46
+ version_requirements: *70243809827540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: capybara
49
- requirement: &70188236596420 !ruby/object:Gem::Requirement
49
+ requirement: &70243809825660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70188236596420
57
+ version_requirements: *70243809825660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70188236595940 !ruby/object:Gem::Requirement
60
+ requirement: &70243809824800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.10.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70188236595940
68
+ version_requirements: *70243809824800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: launchy
71
- requirement: &70188236595480 !ruby/object:Gem::Requirement
71
+ requirement: &70243809741320 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,40 @@ dependencies:
76
76
  version: 2.0.5
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70188236595480
79
+ version_requirements: *70243809741320
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &70243809739840 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.4.5
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70243809739840
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-bundler
93
+ requirement: &70243809739020 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 0.1.3
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70243809739020
102
+ - !ruby/object:Gem::Dependency
103
+ name: genspec
104
+ requirement: &70243809737840 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.1
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70243809737840
80
113
  description: Lightweight string mappings engine for Rails
81
114
  email:
82
115
  - mikebannister@gmail.com
@@ -91,7 +124,6 @@ files:
91
124
  - app/assets/stylesheets/mappable/mappings.css
92
125
  - app/assets/stylesheets/mappable/maps.css
93
126
  - app/assets/stylesheets/scaffold.css
94
- - app/controllers/mappable/application_controller.rb
95
127
  - app/controllers/mappable/mappings_controller.rb
96
128
  - app/controllers/mappable/maps_controller.rb
97
129
  - app/helpers/mappable/application_helper.rb
@@ -137,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
169
  version: '0'
138
170
  segments:
139
171
  - 0
140
- hash: -2016495543354355232
172
+ hash: -1921446453130166665
141
173
  required_rubygems_version: !ruby/object:Gem::Requirement
142
174
  none: false
143
175
  requirements:
@@ -146,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
178
  version: '0'
147
179
  segments:
148
180
  - 0
149
- hash: -2016495543354355232
181
+ hash: -1921446453130166665
150
182
  requirements: []
151
183
  rubyforge_project:
152
184
  rubygems_version: 1.8.10
@@ -1,4 +0,0 @@
1
- module Mappable
2
- class ApplicationController < ActionController::Base
3
- end
4
- end