special_fried_links 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +57 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/lib/special_fried_links.rb +22 -0
- data/test/special_fried_link_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +74 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [Brent Greeff]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
= Special Fried Links
|
2
|
+
|
3
|
+
== Links but with extra tasty bits
|
4
|
+
|
5
|
+
* Ever seen code like this?
|
6
|
+
|
7
|
+
<%= link_to('Edit', edit_something_path(something), :class => 'edit round', :title => "Edit record for #{record.owner}") %>
|
8
|
+
|
9
|
+
* Before you know it your templates start looking like php, and God knows we don't need that.
|
10
|
+
* Obviously the best is to move it into a helper
|
11
|
+
|
12
|
+
module SomethingHelper
|
13
|
+
def link_to_edit_something(something)
|
14
|
+
title = "Edit record for #{record.owner}"
|
15
|
+
path = edit_something_path(something)
|
16
|
+
|
17
|
+
return link_to('Edit', path, :class => 'edit round', :title => title)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
* Nice neat and reusable.
|
22
|
+
|
23
|
+
|
24
|
+
== So whats your point?
|
25
|
+
|
26
|
+
* This plugin allows you to change the calling code from this:
|
27
|
+
|
28
|
+
<%= link_to_edit_something(something) %>
|
29
|
+
|
30
|
+
* to this:
|
31
|
+
|
32
|
+
<%= link_to :edit => something %>
|
33
|
+
|
34
|
+
* Tasty hash syntax
|
35
|
+
|
36
|
+
The downside is that the implementation still needs to be:
|
37
|
+
|
38
|
+
module SomethingHelper
|
39
|
+
def link_to_edit_something(something)
|
40
|
+
title = "Edit record for #{record.owner}"
|
41
|
+
path = edit_something_path(something)
|
42
|
+
|
43
|
+
return link_to('Edit', path, :class => 'edit round', :title => title)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
Or does it?
|
49
|
+
|
50
|
+
|
51
|
+
== Beyond 2000
|
52
|
+
|
53
|
+
It would be nicer if the implementation code was sexier.
|
54
|
+
|
55
|
+
Got ideas? fork it or send me a message.
|
56
|
+
|
57
|
+
Copyright (c) 2009 [Brent Greeff], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the special_fried_link plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the special_fried_link plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'SpecialFriedLink'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module UrlHelper
|
4
|
+
def link_to_with_special_fried(*args, &block)
|
5
|
+
if args.first.is_a? Hash
|
6
|
+
hash = args.first
|
7
|
+
verb = hash.keys.first
|
8
|
+
resource = hash.values.first
|
9
|
+
resource_name = resource.class.name.underscore
|
10
|
+
|
11
|
+
method = "link_to_#{verb}_#{resource_name}".to_sym
|
12
|
+
|
13
|
+
self.send method, resource
|
14
|
+
else
|
15
|
+
link_to_without_special_fried(*args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method_chain :link_to, :special_fried
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: special_fried_links
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brent Greeff
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-30 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Extend Rails link_to with a cool CRUD based dsl.
|
23
|
+
email: email@brentgreeff.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- MIT-LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- MIT-LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- lib/special_fried_links.rb
|
37
|
+
- test/special_fried_link_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/brentgreeff/special_fried_links
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Extend Rails link_to with a cool CRUD based dsl.
|
73
|
+
test_files: []
|
74
|
+
|