link_to_action 0.2.5 → 0.3.0
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 +28 -15
- data/lib/generators/link_to_action/install_generator.rb +19 -5
- data/lib/generators/link_to_action/templates/bootstrap/edit.html.erb +3 -0
- data/lib/generators/link_to_action/templates/bootstrap/index.html.erb +28 -0
- data/lib/generators/link_to_action/templates/bootstrap/new.html.erb +3 -0
- data/lib/generators/link_to_action/templates/bootstrap/show.html.erb +10 -0
- data/lib/generators/link_to_action/templates/link_to_action.rb +1 -1
- data/lib/link_to_action/helpers.rb +3 -3
- data/lib/link_to_action/utils.rb +2 -0
- data/lib/link_to_action/version.rb +1 -1
- metadata +8 -4
data/README.md
CHANGED
@@ -7,6 +7,8 @@ Set of helpers: link_to_new, link_to_index, link_to_show, link_to_edit, link_to_
|
|
7
7
|
|
8
8
|
Bonus helper: link_to_back
|
9
9
|
|
10
|
+
Demo application sources with Twitter Bootstrap enabled: [link_to_action_demo](https://github.com/denispeplin/link_to_action_demo)
|
11
|
+
|
10
12
|
## Why
|
11
13
|
|
12
14
|
Rails scaffold-generated links are not DRY, and it becomes even worse,
|
@@ -30,21 +32,21 @@ And scaffolded code was:
|
|
30
32
|
```
|
31
33
|
|
32
34
|
Even in simple scaffolded link words 'edit' and 'comment' was repeated twice.
|
33
|
-
In more complex example word 'edit' was written three times.
|
35
|
+
In the more complex example word 'edit' was written three times.
|
34
36
|
|
35
|
-
Using link_to_action gem, you can avoid those
|
37
|
+
Using `link_to_action` gem, you can avoid those duplications completely:
|
36
38
|
|
37
39
|
```erb
|
38
40
|
<%= link_to_edit @comment %>
|
39
41
|
```
|
40
42
|
|
41
|
-
That's all for this link, but not all for this gem. It configurable, it can be
|
43
|
+
That's all for this link, but not all for this gem. It is configurable, it can be
|
42
44
|
tuned up to suit other than twitter-bootstrap CSS frameworks (which is off by
|
43
45
|
default anyway), and it even can take advantage of cancan's abilities.
|
44
46
|
|
45
47
|
## When
|
46
48
|
|
47
|
-
This gem is especially useful when application contains many
|
49
|
+
This gem is especially useful when an application contains many similar-looking
|
48
50
|
links. Many global and link-specific options are exists, so this gem is flexible.
|
49
51
|
And you still have `link_to` if you want some link to look really simple!
|
50
52
|
|
@@ -58,12 +60,17 @@ And then execute:
|
|
58
60
|
|
59
61
|
$ bundle
|
60
62
|
|
61
|
-
Add initializer and
|
63
|
+
Add initializer, locale file and templates. Note that CSS classes, icons and
|
64
|
+
cancan are disabled by default. To leave it as it is, just run:
|
62
65
|
|
63
66
|
$ rails generate link_to_action:install
|
64
67
|
|
65
|
-
Edit `config/initializers/link_to_action.rb
|
66
|
-
|
68
|
+
Edit `config/initializers/link_to_action.rb` to change some options. The list of
|
69
|
+
options with defaults provided below.
|
70
|
+
|
71
|
+
To install `link_to_action` with Twitter Bootstrap and icons enabled, run:
|
72
|
+
|
73
|
+
$ rails generate link_to_action:install --bootstrap
|
67
74
|
|
68
75
|
## Usage
|
69
76
|
|
@@ -71,7 +78,8 @@ In general:
|
|
71
78
|
|
72
79
|
link_to_{action} object, options
|
73
80
|
|
74
|
-
Per action, with commented-out link_to equivalents
|
81
|
+
Per action, with commented-out link_to equivalents (no CSS or icons, just to
|
82
|
+
keep it simple):
|
75
83
|
|
76
84
|
```ruby
|
77
85
|
link_to_new MyModel # link_to 'New MyModel', new_my_model_path
|
@@ -83,7 +91,7 @@ link_to_destroy @my_model # link_to 'Delete MyModel', my_model_path(@my_model),
|
|
83
91
|
link_to_back # link_to :back
|
84
92
|
```
|
85
93
|
|
86
|
-
`link_to_show` tries some methods (by default :name
|
94
|
+
`link_to_show` tries some methods (by default :name and :to_s) to get
|
87
95
|
name for the link. This can be changed by specifying `i18n` option. Other
|
88
96
|
helpers use I18n to get link names unless `name` option specified.
|
89
97
|
|
@@ -137,11 +145,11 @@ size_class_default = nil
|
|
137
145
|
size_class_large = 'btn-large'
|
138
146
|
size_class_small = 'btn-small'
|
139
147
|
size_class_mini = 'btn-mini'
|
140
|
-
show_methods = [ :name, :
|
148
|
+
show_methods = [ :name, :to_s ]
|
141
149
|
destroy_confirm = true
|
142
|
-
destroy_skip_pjax = false
|
150
|
+
destroy_skip_pjax = false # overwrite this if pjax is used
|
143
151
|
```
|
144
|
-
Look to `config/initializers/link_to_action.rb` for detailed
|
152
|
+
Look to `config/initializers/link_to_action.rb` for detailed descriptions.
|
145
153
|
|
146
154
|
## Per-link options
|
147
155
|
|
@@ -180,9 +188,14 @@ link_to_new [ @user, Comment ] # /users/1/comments/new
|
|
180
188
|
|
181
189
|
## TODO
|
182
190
|
|
183
|
-
1.
|
184
|
-
2.
|
185
|
-
3.
|
191
|
+
1. Better testing.
|
192
|
+
2. Improve README, add more examples.
|
193
|
+
3. Add templates for Zurb Foundation.
|
194
|
+
4. Whitespace fix in templates.
|
195
|
+
|
196
|
+
## Credits
|
197
|
+
|
198
|
+
This gem was heavily inspired by Platformatec's show_for and simple_form gems. Some code samples were taken from these gems.
|
186
199
|
|
187
200
|
## Contributing
|
188
201
|
|
@@ -6,9 +6,23 @@ module LinkToAction
|
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
desc "Copy LinkToAction configuration file"
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
class_option :bootstrap, type: :boolean,
|
10
|
+
desc: 'Add the Twitter Bootstrap option and templates.'
|
11
|
+
|
12
|
+
def info_framework
|
13
|
+
puts "link_to_action supports Twitter Bootstrap. If you want a " \
|
14
|
+
"configuration that is compatible with this framework, then please " \
|
15
|
+
"re-run this generator with --bootstrap option." unless options.bootstrap?
|
16
|
+
end
|
9
17
|
|
10
18
|
def copy_initializers
|
11
19
|
copy_file 'link_to_action.rb', 'config/initializers/link_to_action.rb'
|
20
|
+
if options[:bootstrap]
|
21
|
+
gsub_file 'config/initializers/link_to_action.rb',
|
22
|
+
%r|# config.use_icons = false|, 'config.use_icons = true'
|
23
|
+
gsub_file 'config/initializers/link_to_action.rb',
|
24
|
+
%r|# config.use_classes = false|, 'config.use_classes = true'
|
25
|
+
end
|
12
26
|
end
|
13
27
|
|
14
28
|
def copy_locale_file
|
@@ -17,11 +31,11 @@ module LinkToAction
|
|
17
31
|
end
|
18
32
|
|
19
33
|
def copy_templates
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
['edit', 'index', 'new', 'show'].each do |action|
|
35
|
+
source_dir = 'bootstrap' if options[:bootstrap]
|
36
|
+
source_file = [ source_dir, "#{action}.html.erb"].compact.join('/')
|
37
|
+
copy_file source_file, "lib/templates/erb/scaffold/#{action}.html.erb"
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<h1>Listing <%= plural_table_name %></h1>
|
2
|
+
|
3
|
+
<table class="table table-condensed">
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
<th><%= attribute.human_name %></th>
|
8
|
+
<% end -%>
|
9
|
+
<th></th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
|
13
|
+
<tbody>
|
14
|
+
<%%= content_tag_for(:tr, @<%= plural_table_name %>) do |<%= singular_table_name %>| %>
|
15
|
+
<% attributes.each do |attribute| -%>
|
16
|
+
<% if attribute.name == 'name' %>
|
17
|
+
<td><%%= link_to_show <%= singular_table_name %> %></td>
|
18
|
+
<% else %>
|
19
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
20
|
+
<% end -%>
|
21
|
+
<% end -%>
|
22
|
+
<td><%%= link_to_edit <%= singular_table_name %>, size: :mini %>
|
23
|
+
<%%= link_to_destroy <%= singular_table_name %>, size: :mini %></td>
|
24
|
+
<%% end %>
|
25
|
+
</tbody>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<%%= link_to_new <%= class_name %> %>
|
@@ -63,11 +63,11 @@ module LinkToAction::Helpers
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def link_to_action(action, object, options)
|
66
|
-
name = options.delete(:name) || LinkToAction::Utils
|
66
|
+
name = options.delete(:name) || LinkToAction::Utils.t_action(object, action)
|
67
67
|
params = options.delete(:params) || {}
|
68
68
|
params[:action] = action if [ :new, :edit ].include? action
|
69
|
-
options[:class] = LinkToAction::Utils
|
70
|
-
name = LinkToAction::Utils
|
69
|
+
options[:class] = LinkToAction::Utils.action_class(action, options)
|
70
|
+
name = LinkToAction::Utils.add_icon_to_name(action, name, options)
|
71
71
|
if link_to_action_cancan?(action, object)
|
72
72
|
link_to name, link_to_action_path(action, object, params), options
|
73
73
|
end
|
data/lib/link_to_action/utils.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_to_action
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -90,6 +90,10 @@ files:
|
|
90
90
|
- Rakefile
|
91
91
|
- lib/generators/link_to_action/USAGE
|
92
92
|
- lib/generators/link_to_action/install_generator.rb
|
93
|
+
- lib/generators/link_to_action/templates/bootstrap/edit.html.erb
|
94
|
+
- lib/generators/link_to_action/templates/bootstrap/index.html.erb
|
95
|
+
- lib/generators/link_to_action/templates/bootstrap/new.html.erb
|
96
|
+
- lib/generators/link_to_action/templates/bootstrap/show.html.erb
|
93
97
|
- lib/generators/link_to_action/templates/edit.html.erb
|
94
98
|
- lib/generators/link_to_action/templates/index.html.erb
|
95
99
|
- lib/generators/link_to_action/templates/link_to_action.rb
|
@@ -162,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
166
|
version: '0'
|
163
167
|
segments:
|
164
168
|
- 0
|
165
|
-
hash: -
|
169
|
+
hash: -2925219352894663217
|
166
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
171
|
none: false
|
168
172
|
requirements:
|
@@ -171,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
175
|
version: '0'
|
172
176
|
segments:
|
173
177
|
- 0
|
174
|
-
hash: -
|
178
|
+
hash: -2925219352894663217
|
175
179
|
requirements: []
|
176
180
|
rubyforge_project:
|
177
181
|
rubygems_version: 1.8.23
|