rails_extras 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # RailsExtras
2
+ [![Gem Version](https://badge.fury.io/rb/rails_extras.png)](http://badge.fury.io/rb/rails_extras)
2
3
 
3
4
  This gem provides extras methods for Rails application.
4
5
 
@@ -18,3 +19,16 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
22
+ ```ruby
23
+ add_link('http://example.com', class: 'text-info') do |tag|
24
+ tag.space "link"
25
+ [1, 2, 3].each do |item|
26
+ tag << item.to_s
27
+ end
28
+ end #=> <a href='http://example.com', class: 'text-info'>link 123</a>
29
+ ```
30
+ # License
31
+
32
+ RailsExtras uses the MIT license. Please check the [LICENSE][] file for more details.
33
+
34
+ [license]: https://github.com/raglub/rails_extras/blob/master/LICENSE
@@ -31,6 +31,25 @@ class RailsExtras
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ def add_link(name = nil, options = nil, html_options = nil, &block)
36
+ if block_given?
37
+ if block.arity == 1
38
+ link_to(name, options) do
39
+ add_tag do |tag|
40
+ block.call(tag)
41
+ end
42
+ end
43
+ else
44
+ link_to(name, options) do
45
+ block.call
46
+ end
47
+ end
48
+ else
49
+ link_to(name, options, html_options)
50
+ end
51
+
52
+ end
34
53
  end
35
54
  end
36
55
  end
@@ -3,7 +3,7 @@ class RailsExtras
3
3
  module Support
4
4
  module Common
5
5
 
6
- def upload_file(path, options={})
6
+ def self.upload_file(path, options={})
7
7
  filename = path.split('/').last.to_s.force_encoding("UTF-8")
8
8
  tempfile = File.new(Rails.root.join('spec', 'files', path))
9
9
  hash = {tempfile: tempfile, filename: filename}
@@ -14,6 +14,9 @@ class RailsExtras
14
14
  ::ActionDispatch::Http::UploadedFile.new(hash)
15
15
  end
16
16
 
17
+ def upload_file(path, options={})
18
+ ::RailsExtras::RSpec::Support::Common.upload_file(path, options)
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -1,3 +1,3 @@
1
1
  class RailsExtras
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -42,4 +42,26 @@ describe ApplicationHelper do
42
42
  # value = 100
43
43
  #end
44
44
  end
45
+
46
+ describe ".add_link" do
47
+ it "should generate link with block without handle" do
48
+ helper.add_link('example.com', class: 'example') do
49
+ 'Example.com'
50
+ end.should eq("<a class=\"example\" href=\"example.com\">Example.com</a>")
51
+ end
52
+
53
+ it "should generate link with block and handle" do
54
+ helper.add_link('example.com', class: 'example') do |tag|
55
+ tag << 'Example'
56
+ tag << 'link'
57
+ tag.space('with')
58
+ tag << 'space!'
59
+ end.should eq("<a class=\"example\" href=\"example.com\">Examplelinkwith space!</a>")
60
+ end
61
+
62
+ it "should generate link without block" do
63
+ helper.add_link('Example.com', 'example.com', class: 'example').should eq("<a class=\"example\" href=\"example.com\">Example.com</a>")
64
+ end
65
+
66
+ end
45
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2014-02-25 00:00:00.000000000 Z
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler