helper_methods 0.0.17 → 0.0.18
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.
- checksums.yaml +7 -0
- data/README.md +14 -5
- data/helper_methods.gemspec +16 -14
- data/lib/helper_methods/version.rb +1 -1
- data/lib/helper_methods.rb +44 -75
- metadata +9 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 090b00a37bf8028c78ab5a0b1c8e653c387c7543
|
4
|
+
data.tar.gz: 26bcaa37bb9fda659265a75095b1f34511b41a62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54ec42fcb84f70f242c6934e5210767c44c9dbad39565613db0c2a8d88137f4f14e0f82a2f96726e7c91ef319ec5c978e29aa626c08db2ac7a31efdf8dfce8a6
|
7
|
+
data.tar.gz: 2c5df953cd70c5c207161cf0a479f51116d51fb30832bbf598989394dd10da7e1c0461a5a17ce67896616c85d770ee22935174992df176f433782f2ed74ca59f
|
data/README.md
CHANGED
@@ -20,17 +20,26 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Included helpers:
|
22
22
|
|
23
|
+
# Common
|
23
24
|
error_messages_for @resource
|
24
25
|
flash_messages
|
26
|
+
active_link_to 'Home', root_path
|
27
|
+
attachment_url file, :style # return full url for attachment
|
28
|
+
full_url_for resource
|
29
|
+
|
30
|
+
# Mobile
|
25
31
|
mobile_device?
|
32
|
+
qr_code_for 'url', 'size in pixels'
|
33
|
+
|
34
|
+
# Youtube
|
26
35
|
youtube('z8WXgoBGRb4')
|
27
36
|
youtube('z8WXgoBGRb4', 720, 480)
|
28
37
|
youtube_link('z8WXgoBGRb4')
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
38
|
+
|
39
|
+
# Bootstrap
|
40
|
+
bootstrap_icon('th-large icon-white')
|
41
|
+
bootstrap_label('Paid', 'success')
|
42
|
+
bootstrap_badge('10', 'info')
|
34
43
|
|
35
44
|
### Youtube helpers
|
36
45
|
|
data/helper_methods.gemspec
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
3
|
require 'helper_methods/version'
|
5
4
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
gem.name = "helper_methods"
|
8
|
-
gem.version = HelperMethods::VERSION
|
9
|
-
gem.authors = ["Francisco Martins"]
|
10
|
-
gem.email = ["franciscomxs@gmail.com"]
|
11
|
-
gem.description = "A small collection of simple methods"
|
12
|
-
gem.summary = "Helper methods that helps you to DRY"
|
13
|
-
gem.homepage = "https://github.com/franciscomxs/helper_methods"
|
5
|
+
Gem::Specification.new do |s|
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
s.name = "helper_methods"
|
8
|
+
s.version = HelperMethods::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.licenses = ["MIT"]
|
11
|
+
s.summary = "Helper methods that helps you to DRY"
|
12
|
+
s.email = ["franciscomxs@gmail.com"]
|
13
|
+
s.homepage = "https://github.com/franciscomxs/helper_methods"
|
14
|
+
s.description = "A small collection of simple methods"
|
15
|
+
s.authors = ["Francisco Martins"]
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ["lib"]
|
19
21
|
|
20
22
|
end
|
data/lib/helper_methods.rb
CHANGED
@@ -4,63 +4,32 @@ require "helper_methods/version"
|
|
4
4
|
|
5
5
|
module HelperMethods
|
6
6
|
|
7
|
-
def error_messages_for(resource, style =
|
7
|
+
def error_messages_for(resource, style = 'danger')
|
8
8
|
if resource.errors.any?
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end.join
|
17
|
-
content += %(</ul>)
|
18
|
-
|
19
|
-
elsif style == :foundation
|
20
|
-
css_class = "alert-box alert"
|
21
|
-
|
22
|
-
content = %(<a href="" class="close">×</a>)
|
23
|
-
content += %(<ul>)
|
24
|
-
resource.errors.collect do |key, value|
|
25
|
-
content += content_tag :li, value
|
26
|
-
end.join
|
27
|
-
content += %(</ul>)
|
28
|
-
end
|
29
|
-
|
30
|
-
content_tag :div, content.html_safe, class: css_class
|
9
|
+
content_tag :div, class: "alert alert-#{style} alert-dismissable" do
|
10
|
+
content_tag :ol do
|
11
|
+
resource.errors.collect do |key, value|
|
12
|
+
content_tag :li, value
|
13
|
+
end.join.html_safe
|
14
|
+
end
|
15
|
+
end
|
31
16
|
end
|
32
17
|
end
|
33
18
|
|
34
|
-
|
35
|
-
def flash_messages(style = :bootstrap)
|
19
|
+
def flash_messages
|
36
20
|
if flash.any?
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
content_tag(:div, content.html_safe, class: "alert alert-#{key}")
|
46
|
-
end
|
47
|
-
end.join.html_safe
|
48
|
-
|
49
|
-
elsif style == :foundation
|
50
|
-
content = %(<a href="" class="close">×</a>)
|
51
|
-
flash.collect do |key, value|
|
52
|
-
unless [true, false, nil].include?(value)
|
53
|
-
key = :success if key == :notice
|
54
|
-
content += value
|
55
|
-
content_tag(:div, content.html_safe, class: "alert-box #{key}")
|
56
|
-
end
|
57
|
-
end.join.html_safe
|
21
|
+
content_tag :div, class: "alert alert-success alert-dismissable" do
|
22
|
+
content_tag :ul do
|
23
|
+
flash.collect do |key, value|
|
24
|
+
unless [true, false, nil].include?(value)
|
25
|
+
content_tag :li, value
|
26
|
+
end
|
27
|
+
end.join.html_safe
|
28
|
+
end
|
58
29
|
end
|
59
|
-
|
60
30
|
end
|
61
31
|
end
|
62
32
|
|
63
|
-
|
64
33
|
def mobile_device?
|
65
34
|
request.user_agent =~ /Mobile|webOS/
|
66
35
|
end
|
@@ -87,6 +56,25 @@ module HelperMethods
|
|
87
56
|
name = "badge-#{name}" unless name.nil?
|
88
57
|
return %(<span class="badge #{name}">#{text}</span>).html_safe
|
89
58
|
end
|
59
|
+
|
60
|
+
def gravatar(email, html_options = {})
|
61
|
+
email = Digest::MD5.hexdigest(email)
|
62
|
+
image_tag "http://www.gravatar.com/avatar/#{email}?size=48", html_options
|
63
|
+
end
|
64
|
+
|
65
|
+
def attachment_url(file, style = :original)
|
66
|
+
protocol = request.ssl? ? 'https' : 'http'
|
67
|
+
"#{protocol}//#{request.host_with_port}#{file.url(style)}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def full_url_for(resource)
|
71
|
+
protocol = request.ssl? ? 'https' : 'http'
|
72
|
+
"#{protocol}//#{request.host_with_port}#{url_for(resource)}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def qr_code_for(data, size)
|
76
|
+
image_tag "https://chart.googleapis.com/chart?chs=#{size}&cht=qr&chl=#{data}"
|
77
|
+
end
|
90
78
|
|
91
79
|
def active_link_to(*args, &block)
|
92
80
|
if block_given?
|
@@ -99,7 +87,7 @@ module HelperMethods
|
|
99
87
|
html_options = args[2] || {}
|
100
88
|
end
|
101
89
|
url = url_for(options)
|
102
|
-
|
90
|
+
|
103
91
|
active_options = { }
|
104
92
|
link_options = { }
|
105
93
|
html_options.each do |k, v|
|
@@ -109,21 +97,21 @@ module HelperMethods
|
|
109
97
|
link_options[k] = v
|
110
98
|
end
|
111
99
|
end
|
112
|
-
|
100
|
+
|
113
101
|
css_class = link_options.delete(:class).to_s + ' '
|
114
102
|
css_class << active_link_to_class(url, active_options)
|
115
103
|
css_class.strip!
|
116
|
-
|
104
|
+
|
117
105
|
wrap_tag = active_options[:wrap_tag].present? ? active_options[:wrap_tag] : nil
|
118
|
-
link_options[:class] = css_class if css_class.present?
|
119
|
-
|
106
|
+
link_options[:class] = css_class if css_class.present?
|
107
|
+
|
120
108
|
link = if active_options[:active_disable] === true && is_active_link?(url, active_options[:active])
|
121
109
|
content_tag(:span, name, link_options)
|
122
110
|
else
|
123
111
|
link_to(name, url, link_options)
|
124
112
|
end
|
125
|
-
|
126
|
-
wrap_tag ? content_tag(wrap_tag, link, :class => css_class) : link
|
113
|
+
|
114
|
+
wrap_tag ? content_tag(wrap_tag, link, :class => (css_class if css_class.present?)) : link
|
127
115
|
end
|
128
116
|
|
129
117
|
def active_link_to_class(url, options = {})
|
@@ -138,7 +126,7 @@ module HelperMethods
|
|
138
126
|
url = url_for(url).sub(/\?.*/, '') # ignore GET params
|
139
127
|
case condition
|
140
128
|
when :inclusive, nil
|
141
|
-
!request.fullpath.match(/^#{Regexp.escape(url)}(\/.*|\?.*)?$/).blank?
|
129
|
+
!request.fullpath.match(/^#{Regexp.escape(url).chomp('/')}(\/.*|\?.*)?$/).blank?
|
142
130
|
when :exclusive
|
143
131
|
!request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
|
144
132
|
when Regexp
|
@@ -154,25 +142,6 @@ module HelperMethods
|
|
154
142
|
false
|
155
143
|
end
|
156
144
|
end
|
157
|
-
|
158
|
-
def gravatar(email, html_options = {})
|
159
|
-
email = Digest::MD5.hexdigest(email)
|
160
|
-
image_tag "http://www.gravatar.com/avatar/#{email}?size=48", html_options
|
161
|
-
end
|
162
|
-
|
163
|
-
def attachment_url(file, style = :original)
|
164
|
-
protocol = request.ssl? ? 'https' : 'http'
|
165
|
-
"#{protocol}//#{request.host_with_port}#{file.url(style)}"
|
166
|
-
end
|
167
|
-
|
168
|
-
def full_url_for(resource)
|
169
|
-
protocol = request.ssl? ? 'https' : 'http'
|
170
|
-
"#{protocol}//#{request.host_with_port}#{url_for(resource)}"
|
171
|
-
end
|
172
|
-
|
173
|
-
def qr_code_for(data, size)
|
174
|
-
image_tag "https://chart.googleapis.com/chart?chs=#{size}&cht=qr&chl=#{data}"
|
175
|
-
end
|
176
145
|
|
177
146
|
end
|
178
147
|
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helper_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.18
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Francisco Martins
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A small collection of simple methods
|
15
14
|
email:
|
@@ -27,27 +26,27 @@ files:
|
|
27
26
|
- lib/helper_methods.rb
|
28
27
|
- lib/helper_methods/version.rb
|
29
28
|
homepage: https://github.com/franciscomxs/helper_methods
|
30
|
-
licenses:
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
31
32
|
post_install_message:
|
32
33
|
rdoc_options: []
|
33
34
|
require_paths:
|
34
35
|
- lib
|
35
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
42
|
requirements:
|
44
|
-
- -
|
43
|
+
- - '>='
|
45
44
|
- !ruby/object:Gem::Version
|
46
45
|
version: '0'
|
47
46
|
requirements: []
|
48
47
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.
|
48
|
+
rubygems_version: 2.1.5
|
50
49
|
signing_key:
|
51
|
-
specification_version:
|
50
|
+
specification_version: 4
|
52
51
|
summary: Helper methods that helps you to DRY
|
53
52
|
test_files: []
|