link_to_action 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -3
- data/lib/generators/link_to_action/install_generator.rb +11 -4
- data/lib/generators/link_to_action/templates/edit.html.erb +6 -0
- data/lib/generators/link_to_action/templates/index.html.erb +33 -0
- data/lib/generators/link_to_action/templates/link_to_action.rb +2 -1
- data/lib/generators/link_to_action/templates/new.html.erb +5 -0
- data/lib/generators/link_to_action/templates/show.html.erb +13 -0
- data/lib/link_to_action/helpers.rb +10 -3
- data/lib/link_to_action/locale/en.yml +3 -2
- data/lib/link_to_action/version.rb +1 -1
- data/lib/link_to_action.rb +5 -2
- data/test/default_values_test.rb +2 -1
- data/test/dummy/log/development.log +24 -0
- data/test/dummy/log/test.log +3842 -9110
- data/test/helpers_test.rb +14 -7
- metadata +38 -34
data/README.md
CHANGED
@@ -46,7 +46,7 @@ default anyway), and it even can take advantage of cancan's abilities.
|
|
46
46
|
|
47
47
|
This gem is especially useful when application contains many simular-looking
|
48
48
|
links. Many global and link-specific options are exists, so this gem is flexible.
|
49
|
-
And you still have link_to if you want some link to look really simple!
|
49
|
+
And you still have `link_to` if you want some link to look really simple!
|
50
50
|
|
51
51
|
## Installation
|
52
52
|
|
@@ -84,7 +84,8 @@ link_to_back # link_to :back
|
|
84
84
|
```
|
85
85
|
|
86
86
|
`link_to_show` tries some methods (by default :name, :title, and :to_s) to get
|
87
|
-
name for the link.
|
87
|
+
name for the link. This can be changed by specifying `i18n` option. Other
|
88
|
+
helpers use I18n to get link names unless `name` option specified.
|
88
89
|
|
89
90
|
## I18n
|
90
91
|
|
@@ -100,13 +101,16 @@ en:
|
|
100
101
|
helpers:
|
101
102
|
link_to:
|
102
103
|
new: 'New %{model}'
|
103
|
-
|
104
|
+
show: 'Show %{model}'
|
105
|
+
index: 'All %{model}'
|
104
106
|
edit: 'Edit %{model}'
|
105
107
|
destroy: 'Delete %{model}'
|
106
108
|
destroy_confirm: 'Are you sure?'
|
107
109
|
back: 'Back'
|
108
110
|
```
|
109
111
|
|
112
|
+
`%{model}` variables are not used by default for `show`, `edit`, and `destroy`.
|
113
|
+
|
110
114
|
## Global CSS styles, icons, and other options
|
111
115
|
|
112
116
|
Default options are:
|
@@ -161,6 +165,7 @@ Look to `config/initializers/link_to_action.rb` for detailed description.
|
|
161
165
|
:name # overwrites default name of the link
|
162
166
|
:send # method to send to object to get name
|
163
167
|
:raw # method to send to object to get name, output raw
|
168
|
+
:i18n # if `i18n: true` is set, I18n name is displayed
|
164
169
|
```
|
165
170
|
|
166
171
|
## Examples
|
@@ -5,17 +5,24 @@ module LinkToAction
|
|
5
5
|
module Generators
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
desc "Copy LinkToAction configuration file"
|
8
|
-
source_root File.expand_path('
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
10
|
def copy_initializers
|
11
|
-
copy_file '
|
12
|
-
'config/initializers/link_to_action.rb'
|
11
|
+
copy_file 'link_to_action.rb', 'config/initializers/link_to_action.rb'
|
13
12
|
end
|
14
13
|
|
15
14
|
def copy_locale_file
|
16
|
-
copy_file 'link_to_action/locale/en.yml',
|
15
|
+
copy_file '../../../link_to_action/locale/en.yml',
|
17
16
|
'config/locales/link_to_action.en.yml'
|
18
17
|
end
|
18
|
+
|
19
|
+
def copy_templates
|
20
|
+
# TODO: one LOC
|
21
|
+
copy_file 'edit.html.erb', 'lib/templates/erb/scaffold/edit.html.erb'
|
22
|
+
copy_file 'index.html.erb', 'lib/templates/erb/scaffold/index.html.erb'
|
23
|
+
copy_file 'new.html.erb', 'lib/templates/erb/scaffold/new.html.erb'
|
24
|
+
copy_file 'show.html.erb', 'lib/templates/erb/scaffold/show.html.erb'
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<h1>Listing <%= plural_table_name %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
<th><%= attribute.human_name %></th>
|
8
|
+
<% end -%>
|
9
|
+
<th></th>
|
10
|
+
<th></th>
|
11
|
+
<th></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
<%%= content_tag_for(:tr, @<%= plural_table_name %>) do |<%= singular_table_name %>| %>
|
17
|
+
<% attributes.each do |attribute| -%>
|
18
|
+
<% if attribute.name == 'name' %>
|
19
|
+
<td><%%= link_to_show <%= singular_table_name %> %></td>
|
20
|
+
<% else %>
|
21
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
22
|
+
<% end -%>
|
23
|
+
<% end -%>
|
24
|
+
<td><%%= link_to_show <%= singular_table_name %>, i18n: true %></td>
|
25
|
+
<td><%%= link_to_edit <%= singular_table_name %> %></td>
|
26
|
+
<td><%%= link_to_destroy <%= singular_table_name %> %></td>
|
27
|
+
<%% end %>
|
28
|
+
</tbody>
|
29
|
+
</table>
|
30
|
+
|
31
|
+
<br />
|
32
|
+
|
33
|
+
<%%= link_to_new <%= class_name %> %>
|
@@ -14,6 +14,7 @@ LinkToAction.setup do |config|
|
|
14
14
|
|
15
15
|
# Icons for actions
|
16
16
|
# config.icon_new = 'plus'
|
17
|
+
# config.icon_show = ''
|
17
18
|
# config.icon_index = '' # empty icon drops it
|
18
19
|
# config.icon_edit = 'edit'
|
19
20
|
# config.icon_destroy = 'trash'
|
@@ -42,7 +43,7 @@ LinkToAction.setup do |config|
|
|
42
43
|
# config.size_class_mini = 'btn-mini'
|
43
44
|
|
44
45
|
# Methods for link_to_show
|
45
|
-
# config.show_methods = [ :name, :
|
46
|
+
# config.show_methods = [ :name, :to_s ]
|
46
47
|
|
47
48
|
# Destroy link options
|
48
49
|
# config.destroy_confirm = true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<p id="notice"><%%= notice %></p>
|
2
|
+
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.human_name %>:</strong>
|
6
|
+
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<%%= link_to_edit @<%= singular_table_name %> %> |
|
12
|
+
<%%= link_to_index <%= class_name %> %> |
|
13
|
+
<%%= link_to_back %>
|
@@ -42,13 +42,20 @@ module LinkToAction::Helpers
|
|
42
42
|
name = options.delete(:name)
|
43
43
|
raw = options.delete(:raw)
|
44
44
|
send = options.delete(:send)
|
45
|
-
|
45
|
+
i18n = options.delete(:i18n)
|
46
|
+
unless name or i18n
|
46
47
|
method = raw || send ||
|
47
48
|
LinkToAction.show_methods.find { |m| object.respond_to?(m) }
|
48
49
|
name = object.send(method)
|
50
|
+
name = raw(name) if raw
|
51
|
+
end
|
52
|
+
|
53
|
+
if i18n
|
54
|
+
options[:name] = name
|
55
|
+
link_to_action :show, object, options
|
56
|
+
else
|
57
|
+
link_to name, object, options
|
49
58
|
end
|
50
|
-
name = raw(name) if raw
|
51
|
-
link_to name, object, options
|
52
59
|
end
|
53
60
|
|
54
61
|
# TODO: Find the way to move this to separate module without loosing access to Rails helpers
|
data/lib/link_to_action.rb
CHANGED
@@ -21,6 +21,9 @@ module LinkToAction
|
|
21
21
|
mattr_accessor :icon_new
|
22
22
|
@@icon_new = 'plus'
|
23
23
|
|
24
|
+
mattr_accessor :icon_show
|
25
|
+
@@icon_show = ''
|
26
|
+
|
24
27
|
mattr_accessor :icon_index
|
25
28
|
@@icon_index = ''
|
26
29
|
|
@@ -32,7 +35,7 @@ module LinkToAction
|
|
32
35
|
|
33
36
|
mattr_accessor :icon_back
|
34
37
|
@@icon_back = 'undo'
|
35
|
-
|
38
|
+
|
36
39
|
mattr_accessor :use_classes
|
37
40
|
@@use_classes = false
|
38
41
|
|
@@ -70,7 +73,7 @@ module LinkToAction
|
|
70
73
|
@@size_class_mini = 'btn-mini'
|
71
74
|
|
72
75
|
mattr_accessor :show_methods
|
73
|
-
@@show_methods = [ :name, :
|
76
|
+
@@show_methods = [ :name, :to_s ]
|
74
77
|
|
75
78
|
mattr_accessor :destroy_confirm
|
76
79
|
@@destroy_confirm = true
|
data/test/default_values_test.rb
CHANGED
@@ -7,6 +7,7 @@ class DefaultValuesTest < ActiveSupport::TestCase
|
|
7
7
|
icons_size: 'large',
|
8
8
|
icons_place_left: true,
|
9
9
|
icon_new: 'plus',
|
10
|
+
icon_show: '',
|
10
11
|
icon_index: '',
|
11
12
|
icon_edit: 'edit',
|
12
13
|
icon_destroy: 'trash',
|
@@ -23,7 +24,7 @@ class DefaultValuesTest < ActiveSupport::TestCase
|
|
23
24
|
size_class_large: 'btn-large',
|
24
25
|
size_class_small: 'btn-small',
|
25
26
|
size_class_mini: 'btn-mini',
|
26
|
-
show_methods: [ :name, :
|
27
|
+
show_methods: [ :name, :to_s ],
|
27
28
|
destroy_confirm: true,
|
28
29
|
destroy_skip_pjax: false
|
29
30
|
}
|
@@ -1 +1,25 @@
|
|
1
1
|
Connecting to database specified by database.yml
|
2
|
+
Connecting to database specified by database.yml
|
3
|
+
Connecting to database specified by database.yml
|
4
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
5
|
+
[1m[35m (4.3ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
6
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
7
|
+
[1m[35m (1.5ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
8
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
9
|
+
Migrating to CreateUsers (20121003103906)
|
10
|
+
[1m[35m (0.0ms)[0m begin transaction
|
11
|
+
[1m[36m (0.7ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
12
|
+
[1m[35m (0.3ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20121003103906')
|
13
|
+
[1m[36m (1.6ms)[0m [1mcommit transaction[0m
|
14
|
+
Migrating to CreateComments (20121003103958)
|
15
|
+
[1m[35m (0.1ms)[0m begin transaction
|
16
|
+
[1m[36m (0.3ms)[0m [1mCREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "user_id" integer, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
17
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("comments")
|
18
|
+
[1m[36m (0.1ms)[0m [1mCREATE INDEX "index_comments_on_user_id" ON "comments" ("user_id")[0m
|
19
|
+
[1m[35m (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20121003103958')
|
20
|
+
[1m[36m (1.4ms)[0m [1mcommit transaction[0m
|
21
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
22
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
23
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("comments")
|
24
|
+
[1m[36m (0.0ms)[0m [1mPRAGMA index_info('index_comments_on_user_id')[0m
|
25
|
+
[1m[35m (0.0ms)[0m PRAGMA index_list("users")
|