icon_links 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,53 @@
1
- IconLinks
2
- =========
3
- Easily link icons of your choosing with handy helpers. Works great with Silk icons.
1
+ Icon Links - Change boring Rails text links to sexy icon_to links
2
+ =================================================================
3
+ Rails comes with `link_to`, `link_to_remote`, and other helpers to easily create text links. But it's 2010. I remember being impressed by text links. It was 1995.
4
4
 
5
+ This gem enables you to easily create links using icons of your choosing. It provides handy Rails view helper methods that encapsulate repetitive tasks, such as resolving image paths. This gem works great with the venerable [Fam Fam Fam Silk Icons](http://www.famfamfam.com/lab/icons/silk/), but it also works equally well with any other icon set you have as well.
5
6
 
6
7
  Example
7
8
  =======
8
- Example goes here.
9
+ If you download the [Silk Icons](http://www.famfamfam.com/lab/icons/silk/) and unzip them to `public/images/icons`, you then only need to change the standard Rails `link_to` idioms:
9
10
 
10
- Copyright (c) 2008-2010 [Nate Wiger](http://nateware.com), released under the MIT license.
11
+ link_to 'Show', post_path(@post)
12
+ link_to 'Edit', edit_post_path(@post)
13
+ link_to 'Destroy', post_path(@post), :confirm => 'Are you sure?', :method => :delete
14
+ link_to 'Back', post_path
15
+
16
+ To use `icon_to`:
17
+
18
+ icon_to :show, post_path(@post)
19
+ icon_to :edit, edit_post_path(@post)
20
+ icon_to :delete, post_path(@post), :confirm => 'Are you sure?', :method => :delete
21
+ icon_to :back, posts_path
22
+
23
+ And you'll get snazzy, linked silk icons that will make you cry.
24
+
25
+ You can even go one fancier, and use REST route helpers with an `_icon` suffix:
26
+
27
+ post_icon(@post)
28
+ edit_post_icon(@post)
29
+ delete_post_icon(@post, :confirm => 'Are you sure?', :method => :delete)
30
+
31
+ Yeah, this plugin is simple and sweet. Sugary, like candy.
32
+
33
+ If you want to relocate your icons or choose a different image type:
34
+
35
+ IconLinks.icon_image_url = '/images/thingies'
36
+ IconLinks.icon_image_suffix = '.gif'
37
+
38
+ You can also create completely custom mappings of icons to paths:
39
+
40
+ IconLinks.custom_icon_images = {
41
+ :loading => "/images/misc/loading.gif"
42
+ }
43
+
44
+ Now, you can do:
45
+
46
+ icon_to :loading, loading_path
47
+
48
+ And you will get your custom icon.
49
+
50
+ Author
51
+ ======
52
+ Copyright (c) 2008-2010 [Nate Wiger](http://nateware.com). All Rights Reserved.
53
+ Released under the MIT license.
@@ -1,6 +1,5 @@
1
1
  # IconLinks
2
2
  require 'active_support/core_ext/module/attribute_accessors'
3
-
4
3
  module IconLinks
5
4
  # Relative path to the icons
6
5
  mattr_accessor :icon_image_url
@@ -29,7 +28,4 @@ module IconLinks
29
28
  end
30
29
  end
31
30
 
32
- require 'icon_links/view_helpers'
33
- require 'icon_links/method_missing'
34
-
35
- ActionView::Base.send :include, IconLinks if defined?(ActionView::Base)
31
+ ActionView::Base.send :include, IconLinks if defined?(ActionView::Base)
@@ -32,25 +32,25 @@ module IconLinks
32
32
  url = send("new_#{meth}_path", options)
33
33
  #options[:rel] = "gb_page_center[600, 500]" # greybox
34
34
  options[:title] ||= "Create a new #{label}"
35
- return link_icon(icon, url, options)
35
+ return icon_to(icon, url, options)
36
36
 
37
37
  when 'ajaxnew'
38
38
  url = send("new_#{meth}_path", options)
39
39
  #options[:rel] = "gb_page_center[600, 500]" # greybox
40
40
  options[:title] ||= "Create a new #{label}"
41
- return link_icon(icon, url, options)
41
+ return icon_to(icon, url, options)
42
42
 
43
43
  when 'edit'
44
44
  url = send("edit_#{meth}_path", args)
45
45
  #options[:rel] = "gb_page_center[600, 500]" # greybox
46
46
  options[:title] ||= "Edit this #{label}"
47
- return link_icon(icon, url, options)
47
+ return icon_to(icon, url, options)
48
48
 
49
49
  when 'delete'
50
50
  url = send("#{meth}_path", args)
51
51
  options[:method] ||= :delete
52
52
  options[:title] ||= "Delete this #{label}"
53
- return link_icon(icon, url, options)
53
+ return icon_to(icon, url, options)
54
54
 
55
55
  when 'ajaxdelete'
56
56
  # Delete a record with an id, ala user_path(user)
@@ -142,7 +142,7 @@ module IconLinks
142
142
  # main index, this does NOT have an id
143
143
  url = send("#{meth}_path", args)
144
144
  options[:title] ||= "View this #{label}"
145
- return link_icon(icon, url, options)
145
+ return icon_to(icon, url, options)
146
146
  else
147
147
  # This generic handler handles all other actions
148
148
  options[:title] ||= "#{type.titleize} this #{label}"
@@ -164,7 +164,7 @@ module IconLinks
164
164
  options[:url] = url
165
165
  return link_to_remote(icon_tag(icon), options, htmlopt)
166
166
  else
167
- return link_icon(icon, url, options)
167
+ return icon_to(icon, url, options)
168
168
  end
169
169
  end
170
170
  end
@@ -174,10 +174,9 @@ module IconLinks
174
174
  end
175
175
 
176
176
  # Override Rails CDATA JS wrapper because it kills AJAX requests (doh!)
177
- #module ActionView::Helpers::JavaScriptHelper
178
- # def javascript_tag(content, html_options = {})
179
- # content_tag("script", content,
180
- # html_options.merge(:type => "text/javascript"))
181
- # end
182
- #end
183
-
177
+ module ActionView::Helpers::JavaScriptHelper
178
+ def javascript_tag(content, html_options = {})
179
+ content_tag("script", content,
180
+ html_options.merge(:type => "text/javascript"))
181
+ end
182
+ end
@@ -5,7 +5,7 @@ module IconLinks
5
5
 
6
6
  # This creates a link using the specified type of icon. The args
7
7
  # accepted are the exact same as the args for +link_to+.
8
- def link_icon(text, *args)
8
+ def icon_to(text, *args)
9
9
  if args.first.is_a?(Hash)
10
10
  return icon_tag(:clear) unless args[0].delete(:if)
11
11
  end
@@ -14,20 +14,20 @@ module IconLinks
14
14
 
15
15
  # This creates a link using the specified type of icon. The args
16
16
  # accepted are the exact same as the args for +link_to_remote+.
17
- def link_icon_remote(text, *args)
17
+ def icon_to_remote(text, *args)
18
18
  if args.first.is_a?(Hash)
19
19
  return icon_tag(:clear) unless args[0].delete(:if)
20
20
  end
21
21
  link_to_remote(icon_for(text), *args)
22
22
  end
23
23
 
24
- # This is similar to link_icon, only it is designed to call a JS function
24
+ # This is similar to icon_to, only it is designed to call a JS function
25
25
  def function_icon(text, function)
26
26
  link_to(icon_for(text), '#', :onclick => function)
27
27
  end
28
28
 
29
29
  # This expands the text and returns the icon path. It is used internally
30
- # by +link_icon+ and +link_icon_remote+ to render the link text.
30
+ # by +icon_to+ and +icon_to_remote+ to render the link text.
31
31
  def icon_for(text, excess=nil)
32
32
  link = nil
33
33
  if text.is_a? Array
@@ -61,7 +61,7 @@ module IconLinks
61
61
  }.update(options)
62
62
  end
63
63
 
64
- # This returns a help link similar to +link_icon+, only using the help
64
+ # This returns a help link similar to +icon_to+, only using the help
65
65
  # from the system_help table. If no help is found, then an empty
66
66
  # string is returned (allowing you to randomly call this on any
67
67
  # object, without having to check if help exists first).
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nate Wiger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-07 00:00:00 -07:00
17
+ date: 2010-05-10 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: "2.3"
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
- description: Easily replace text links with icons in Rails views with handy link_icon helpers.
33
+ description: Easily replace boring Rails text links with sexy icons. Includes handy icon_to helpers.
34
34
  email: nate@wiger.org
35
35
  executables: []
36
36
 
@@ -78,6 +78,6 @@ rubyforge_project: icon_links
78
78
  rubygems_version: 1.3.6
79
79
  signing_key:
80
80
  specification_version: 3
81
- summary: Replace text links with icons in Rails views with handy icon_links helpers.
81
+ summary: Easily replace boring Rails text links with sexy icons.
82
82
  test_files: []
83
83