linkify 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -9
- data/lib/linkify/version.rb +1 -1
- data/lib/linkify/view_helper.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Linkify
|
2
2
|
|
3
|
-
Linkify makes it possible to list all records from specific models in a grouped_options_for_select array. This can by very useful for internal linking. It doesn't return absolute or relative paths by default, but instead gives you the model name and identifier (usually ID) of a record, so you
|
3
|
+
Linkify makes it possible to list all records from specific models in a grouped_options_for_select array. This can by very useful for internal linking. It doesn't return absolute or relative paths by default, but instead gives you the model name and identifier (usually ID) of a record, so you'll have to create your own logic for generating links from this information afterwards.
|
4
4
|
|
5
5
|
This gem integrates easily with any Rails app using ActiveRecord.
|
6
6
|
|
@@ -8,7 +8,7 @@ This gem integrates easily with any Rails app using ActiveRecord.
|
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
gem '
|
11
|
+
gem 'linkify'
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
@@ -16,7 +16,7 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install linkify
|
20
20
|
|
21
21
|
## Example output
|
22
22
|
<select>
|
@@ -29,12 +29,12 @@ Or install it yourself as:
|
|
29
29
|
</select>
|
30
30
|
## Usage
|
31
31
|
|
32
|
-
Want to add a 'link to page' drop down in a form, simply call the `internal_links` method for the options_for_select parameter.
|
32
|
+
Want to add a 'link to page' drop down in a form, simply call the `internal_links` method for the options_for_select parameter. It requires the current value as a parameter.
|
33
33
|
|
34
34
|
Example:
|
35
35
|
|
36
36
|
<%= form_for @link do |f| %>
|
37
|
-
<%= f.select :url_options, internal_links %>
|
37
|
+
<%= f.select :url_options, internal_links(@link.url_options) %>
|
38
38
|
...
|
39
39
|
<%= f.submit %>
|
40
40
|
<% end %>
|
@@ -44,22 +44,26 @@ Example:
|
|
44
44
|
By default, no records will return if you call this method. For each model you want to list, you have to add this method to the model:
|
45
45
|
|
46
46
|
linkable_by :title, :id
|
47
|
+
|
48
|
+
or, to not show only a selection of records:
|
49
|
+
|
50
|
+
linkable_by :title, :id, limit(10)
|
47
51
|
|
48
|
-
It takes
|
52
|
+
It takes three parameters:
|
49
53
|
|
50
54
|
1. the name you'll see in the `<option>`
|
51
55
|
2. the value that will be in the `<option>`
|
52
|
-
3. the
|
56
|
+
3. the collection of records from this model (defaults to `all` but could also be a (named) scope or custom method)
|
53
57
|
|
54
58
|
## Add extra pages (static pages for example)
|
55
59
|
Sometimes you want to not only list records from the database, but also static pages: home, contact, about, etc. To add these to the `<select>` too, you can pass them as a parameter to the `internal_links` method:
|
56
60
|
|
57
|
-
<%=
|
61
|
+
<%= f.select :url_options, internal_links(@link.url_options, [["contact", "/contact"], ["about", "/about"]]) %>
|
58
62
|
|
59
63
|
I don't like to link to URL's directly but prefer to link to a Rails helper method instead. For example:
|
60
64
|
|
61
65
|
# in the form
|
62
|
-
<%=
|
66
|
+
<%= f.select :url_options, internal_links(@link.url_options, [["contact", "contact_path"], ["about", "about_path"]]) %>
|
63
67
|
|
64
68
|
# in the place I need to show this link
|
65
69
|
<%= link_to @link.name, send(@link.path)%>
|
data/lib/linkify/version.rb
CHANGED
data/lib/linkify/view_helper.rb
CHANGED
@@ -5,8 +5,8 @@ module Linkify
|
|
5
5
|
|
6
6
|
|
7
7
|
# renders a select
|
8
|
-
def internal_links(additional_pages=[])
|
9
|
-
grouped_options_for_select(grouped_options(additional_pages))
|
8
|
+
def internal_links(current_object, additional_pages=[])
|
9
|
+
grouped_options_for_select(grouped_options(additional_pages), current_object)
|
10
10
|
end
|
11
11
|
|
12
12
|
def all_models
|