happy-helpers 0.1.0.pre6 → 0.1.0.pre7

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'tilt', '~> 1.3'
19
19
  gem.add_dependency 'i18n'
20
20
  gem.add_dependency 'money', '~> 5.0'
21
+ gem.add_dependency 'activesupport'
21
22
 
22
23
  gem.add_development_dependency 'rspec'
23
24
  gem.add_development_dependency 'rake'
@@ -28,16 +28,17 @@ module HappyHelpers
28
28
  end
29
29
 
30
30
  def url_for(*what)
31
- return what.first if what.size == 1 && what.first.is_a?(String)
32
-
33
- what.flatten.inject('') do |url, item|
31
+ result = what.flatten.inject('') do |url, item|
34
32
  url << "/%s" % case item
35
33
  when String, Symbol then item.to_s
34
+ when NilClass then "/"
36
35
  else "%s/%s" % [item.class.to_s.tableize.pluralize, item.try(:to_param) || item.try(:to_id) || item.try(:id)]
37
36
  end
38
37
 
39
38
  url
40
- end
39
+ end.gsub(/\/{2,}/, '/').chomp('/')
40
+
41
+ result == "" ? '/' : result
41
42
  end
42
43
 
43
44
  def capture(*args, &block)
@@ -1,3 +1,3 @@
1
1
  module HappyHelpers
2
- VERSION = "0.1.0.pre6"
2
+ VERSION = "0.1.0.pre7"
3
3
  end
data/lib/happy-helpers.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'active_support/inflector'
2
+ require 'active_support/core_ext'
3
+
1
4
  require "happy-helpers/version"
2
5
  require 'happy-helpers/helpers'
3
6
  require 'happy-helpers/templates'
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ module HappyHelpers
5
+ module Helpers
6
+ describe Html do
7
+ include Html
8
+
9
+ describe "#url_for" do
10
+ it "generates a url from an array of strings" do
11
+ url_for('foo', 'bar', '123').should == '/foo/bar/123'
12
+ end
13
+
14
+ it "removes duplicate dashes" do
15
+ url_for('/foo/', 'bar').should == '/foo/bar'
16
+ end
17
+
18
+ it "removes leading dashes" do
19
+ url_for('foo/').should == '/foo'
20
+ end
21
+
22
+ it "returns just a slash if no parameters are given" do
23
+ url_for().should == '/'
24
+ end
25
+
26
+ it "doesn't take nil into account" do
27
+ url_for('foo', nil, 'bar').should == '/foo/bar'
28
+ end
29
+
30
+ it "also accepts symbols" do
31
+ url_for(:foo, 'bar').should == '/foo/bar'
32
+ end
33
+
34
+ it "generates RESTful URLs from objects" do
35
+ url_for(mock(:class => 'thingy', :to_param => '1')).should == '/thingies/1'
36
+ end
37
+
38
+ it "is can be cascaded" do
39
+ url_for(url_for(:foo, :bar), '123', url_for('woop')).should == '/foo/bar/123/woop'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre6
4
+ version: 0.1.0.pre7
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
16
- requirement: &70128872890840 !ruby/object:Gem::Requirement
16
+ requirement: &70100401606860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70128872890840
24
+ version_requirements: *70100401606860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &70128872890140 !ruby/object:Gem::Requirement
27
+ requirement: &70100401606300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70128872890140
35
+ version_requirements: *70100401606300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: money
38
- requirement: &70128872888880 !ruby/object:Gem::Requirement
38
+ requirement: &70100401605700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '5.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70128872888880
46
+ version_requirements: *70100401605700
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &70100401605260 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70100401605260
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec
49
- requirement: &70128872887000 !ruby/object:Gem::Requirement
60
+ requirement: &70100401604760 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70128872887000
68
+ version_requirements: *70100401604760
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rake
60
- requirement: &70128872885920 !ruby/object:Gem::Requirement
71
+ requirement: &70100401604180 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70128872885920
79
+ version_requirements: *70100401604180
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: watchr
71
- requirement: &70128872884460 !ruby/object:Gem::Requirement
82
+ requirement: &70100401603420 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,7 +87,7 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70128872884460
90
+ version_requirements: *70100401603420
80
91
  description: View helpers for your custom Rack app or framework.
81
92
  email:
82
93
  - hendrik@mans.de
@@ -101,6 +112,7 @@ files:
101
112
  - lib/happy-helpers/templates.rb
102
113
  - lib/happy-helpers/utils/date_parameter_converter.rb
103
114
  - lib/happy-helpers/version.rb
115
+ - spec/helpers/html_spec.rb
104
116
  - spec/helpers/numbers_spec.rb
105
117
  - spec/spec_helper.rb
106
118
  homepage: https://github.com/hmans/happy-helpers
@@ -128,6 +140,7 @@ signing_key:
128
140
  specification_version: 3
129
141
  summary: View helpers for your custom Rack app or framework.
130
142
  test_files:
143
+ - spec/helpers/html_spec.rb
131
144
  - spec/helpers/numbers_spec.rb
132
145
  - spec/spec_helper.rb
133
146
  has_rdoc: