happy-helpers 0.1.0.pre12 → 0.1.0.pre13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -27
- data/lib/happy-helpers/helpers.rb +0 -4
- data/lib/happy-helpers/version.rb +1 -1
- metadata +14 -19
- data/lib/happy-helpers/helpers/html.rb +0 -55
- data/lib/happy-helpers/helpers/i18n.rb +0 -13
- data/lib/happy-helpers/utils/date_parameter_converter.rb +0 -25
- data/spec/helpers/html_spec.rb +0 -48
data/README.md
CHANGED
@@ -1,29 +1,3 @@
|
|
1
1
|
# HappyHelpers
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'happy-helpers'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install happy-helpers
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
3
|
+
**Deprecated, as most helpers have moved into the core Happy framework.**
|
@@ -1,12 +1,8 @@
|
|
1
|
-
require 'happy-helpers/helpers/html'
|
2
1
|
require 'happy-helpers/helpers/forms'
|
3
|
-
require 'happy-helpers/helpers/i18n'
|
4
2
|
require 'happy-helpers/helpers/numbers'
|
5
3
|
|
6
4
|
module HappyHelpers
|
7
5
|
module Helpers
|
8
|
-
include Html
|
9
|
-
include I18n
|
10
6
|
include Forms
|
11
7
|
include Numbers
|
12
8
|
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.
|
4
|
+
version: 0.1.0.pre13
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &70348822630900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70348822630900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: money
|
27
|
-
requirement: &
|
27
|
+
requirement: &70348822630400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '5.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70348822630400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &70348822629980 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70348822629980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70348822629520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70348822629520
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70348822629100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70348822629100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: watchr
|
71
|
-
requirement: &
|
71
|
+
requirement: &70348822628680 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70348822628680
|
80
80
|
description: View helpers for your custom Rack app or framework.
|
81
81
|
email:
|
82
82
|
- hendrik@mans.de
|
@@ -95,12 +95,8 @@ files:
|
|
95
95
|
- lib/happy-helpers.rb
|
96
96
|
- lib/happy-helpers/helpers.rb
|
97
97
|
- lib/happy-helpers/helpers/forms.rb
|
98
|
-
- lib/happy-helpers/helpers/html.rb
|
99
|
-
- lib/happy-helpers/helpers/i18n.rb
|
100
98
|
- lib/happy-helpers/helpers/numbers.rb
|
101
|
-
- lib/happy-helpers/utils/date_parameter_converter.rb
|
102
99
|
- lib/happy-helpers/version.rb
|
103
|
-
- spec/helpers/html_spec.rb
|
104
100
|
- spec/helpers/numbers_spec.rb
|
105
101
|
- spec/spec_helper.rb
|
106
102
|
homepage: https://github.com/hmans/happy-helpers
|
@@ -128,7 +124,6 @@ signing_key:
|
|
128
124
|
specification_version: 3
|
129
125
|
summary: View helpers for your custom Rack app or framework.
|
130
126
|
test_files:
|
131
|
-
- spec/helpers/html_spec.rb
|
132
127
|
- spec/helpers/numbers_spec.rb
|
133
128
|
- spec/spec_helper.rb
|
134
129
|
has_rdoc:
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext'
|
2
|
-
require 'cgi'
|
3
|
-
|
4
|
-
module HappyHelpers
|
5
|
-
module Helpers
|
6
|
-
module Html
|
7
|
-
def html_tag(name, options = nil, escape = true, &block)
|
8
|
-
"<#{name} #{html_tag_attributes(options, escape) if options}#{block_given? ? ">#{yield if block_given?}</#{name}>" : " />"}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def html_tag_attributes(options, escape = true)
|
12
|
-
options.map do |k,v|
|
13
|
-
if v
|
14
|
-
v == true ? "#{k}" : "#{k}=\"#{ escape_html(v) }\""
|
15
|
-
end
|
16
|
-
end.compact.join(" ")
|
17
|
-
end
|
18
|
-
|
19
|
-
def escape_html(t)
|
20
|
-
#Rack::Utils.escape_html(t.to_s)
|
21
|
-
CGI::escape_html(t.to_s)
|
22
|
-
end
|
23
|
-
|
24
|
-
def preserve(t)
|
25
|
-
t.chomp("\n").gsub(/\n/, '
').gsub(/\r/, '')
|
26
|
-
end
|
27
|
-
|
28
|
-
def link_to(name, *target)
|
29
|
-
options = target.last.is_a?(Hash) ? target.pop : {}
|
30
|
-
html_tag(:a, options.merge(:href => url_for(*target))) { name }
|
31
|
-
end
|
32
|
-
|
33
|
-
def url_for(*what)
|
34
|
-
return what.first if what.size == 1 && what.first =~ %r{://}
|
35
|
-
|
36
|
-
result = what.flatten.inject('') do |url, item|
|
37
|
-
url << "/%s" % case item
|
38
|
-
when String, Symbol then item.to_s
|
39
|
-
when NilClass then "/"
|
40
|
-
else "%s/%s" % [item.class.to_s.tableize.pluralize, item.try(:to_param) || item.try(:to_id) || item.try(:id)]
|
41
|
-
end
|
42
|
-
|
43
|
-
url
|
44
|
-
end.gsub(/\/{2,}/, '/').chomp('/')
|
45
|
-
|
46
|
-
result == "" ? '/' : result
|
47
|
-
end
|
48
|
-
|
49
|
-
def capture(*args, &block)
|
50
|
-
# TODO: support more than just HAML. :P~
|
51
|
-
capture_haml(*args, &block)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module HappyHelpers
|
2
|
-
module Utils
|
3
|
-
module DateParameterConverter
|
4
|
-
class << self
|
5
|
-
def convert!(params)
|
6
|
-
params.each do |k, v|
|
7
|
-
if looks_like_a_date?(v)
|
8
|
-
params[k] = convert_to_date(v)
|
9
|
-
elsif v.is_a? Hash
|
10
|
-
convert!(v)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def looks_like_a_date?(v)
|
16
|
-
v.is_a?(Hash) && v.has_key?('year') && v.has_key?('month') && v.has_key?('day')
|
17
|
-
end
|
18
|
-
|
19
|
-
def convert_to_date(v)
|
20
|
-
DateTime.new(v['year'].to_i, v['month'].to_i, v['day'].to_i, v['hour'].to_i, v['minute'].to_i, v['second'].to_i)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/helpers/html_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
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
|
-
|
42
|
-
it "doesn't modify strings containing complete URLs" do
|
43
|
-
url_for('http://www.test.com').should == 'http://www.test.com'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|