helper_methods 0.0.20 → 1.0.0.rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfc593978e3c1dfdd61040bbeffdaf79d6f88973
4
- data.tar.gz: 569ef38e86cc57c35d57def54088fd15e9a5078a
3
+ metadata.gz: 24f01c10ecb456e684d0eb7f3f93d364c8cddce4
4
+ data.tar.gz: 2e679a8275f2ab6b9ad3a6d063d4c0ebc3888453
5
5
  SHA512:
6
- metadata.gz: a1e0cd6597efa633bf2eed5efca2782ffe09a8ffe6c6182f5460c9cbf2662f86f8a7a776907ededed3343d3f8d78485b13b0f3c3ca1361bf06113ce37daca031
7
- data.tar.gz: 467b5ae9165c5d5e8a3a48e58c470431d2aba4349b11b54ba8e0d9aaf925a5ed06d058ec7509ae068abb3ccacaf0e9e7c4bb67f521ffcfc3bafe462a2d16047f
6
+ metadata.gz: 1f14ae87bee92d04ce44d945ce01dab51b93e12ba78c0c4a3d11bf011742e7db54a47b7918c2703faa5e492e328e032bbb65f32ffd490317ee85c66060abc84d
7
+ data.tar.gz: c425b153fcc1bb117ad52297cdf418f09670cb2d8ddec44b68add95f0e40474a5259ae4711a1016d25d6e732a457f3e0598ee98a085e287c01e3ced8ec1f890b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ helper_methods
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
@@ -2,21 +2,25 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'helper_methods/version'
4
4
 
5
- Gem::Specification.new do |s|
5
+ Gem::Specification.new do |spec|
6
6
 
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"]
7
+ spec.name = 'helper_methods'
8
+ spec.version = HelperMethods::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.summary = 'Helper methods that helps you to DRY'
11
+ spec.email = 'franciscomxs@gmail.com'
12
+ spec.homepage = 'https://github.com/franciscomxs/helper_methods'
13
+ spec.description = 'A small collection of simple methods'
14
+ spec.authors = ['Francisco Martins']
15
+ spec.licenses = 'MIT'
21
16
 
22
- end
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_dependency 'rails', '~> 4'
25
+
26
+ end
@@ -1,146 +1,18 @@
1
- # encoding: UTF-8
2
-
3
- require "helper_methods/version"
1
+ require 'helper_methods/version'
4
2
 
5
3
  module HelperMethods
6
-
7
- def error_messages_for(resource, style = 'danger')
8
- if resource.errors.any?
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
16
- end
17
- end
18
-
19
- def flash_messages
20
- if flash.any?
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
29
- end
30
- end
31
- end
32
-
33
- def mobile_device?
34
- request.user_agent =~ /Mobile|webOS/
35
- end
36
-
37
- def youtube_videop(video, width = 580, height = 420)
38
- "<iframe width='#{width}' height='#{height}' src='http://www.youtube.com/embed/#{video}' frameborder='0' allowfullscreen></iframe>".html_safe
39
- end
40
-
41
- def youtube_link(video)
42
- link_to "www.youtube.com/watch?v=#{video}", "http://www.youtube.com/watch?v=#{video}", class: 'various fancybox-media'
43
- end
44
-
45
- def bootstrap_icon(name, text="", direction="l")
46
- return %(<span class="#{name}"></span> #{text}).html_safe if direction == 'l'
47
- return %(#{text} <span class="#{name}"></span>).html_safe if direction == 'r'
48
- end
49
-
50
- def bootstrap_label(text, name="")
51
- return %(<span class="#{name}">#{text}</span>).html_safe
52
- end
53
-
54
- def bootstrap_badge(text, name="")
55
- return %(<span class="#{name}">#{text}</span>).html_safe
56
- end
57
-
58
- def gravatar(email, html_options = {})
59
- email = Digest::MD5.hexdigest(email)
60
- image_tag "http://www.gravatar.com/avatar/#{email}?size=48", html_options
61
- end
62
-
63
- def attachment_url(file, style = :original)
64
- protocol = request.ssl? ? 'https' : 'http'
65
- "#{protocol}//#{request.host_with_port}#{file.url(style)}"
66
- end
67
-
68
- def full_url_for(resource)
69
- protocol = request.ssl? ? 'https' : 'http'
70
- "#{protocol}//#{request.host_with_port}#{url_for(resource)}"
71
- end
72
-
73
- def qr_code_for(data, size)
74
- image_tag "https://chart.googleapis.com/chart?chs=#{size}&cht=qr&chl=#{data}"
75
- end
76
-
77
- def active_link_to(*args, &block)
78
- if block_given?
79
- name = capture(&block)
80
- options = args[0] || {}
81
- html_options = args[1] || {}
82
- else
83
- name = args[0]
84
- options = args[1] || {}
85
- html_options = args[2] || {}
86
- end
87
- url = url_for(options)
88
-
89
- active_options = { }
90
- link_options = { }
91
- html_options.each do |k, v|
92
- if [:active, :class_active, :class_inactive, :active_disable, :wrap_tag].member?(k)
93
- active_options[k] = v
94
- else
95
- link_options[k] = v
96
- end
97
- end
98
-
99
- css_class = link_options.delete(:class).to_s + ' '
100
- css_class << active_link_to_class(url, active_options)
101
- css_class.strip!
102
-
103
- wrap_tag = active_options[:wrap_tag].present? ? active_options[:wrap_tag] : nil
104
- link_options[:class] = css_class if css_class.present?
105
-
106
- link = if active_options[:active_disable] === true && is_active_link?(url, active_options[:active])
107
- content_tag(:span, name, link_options)
108
- else
109
- link_to(name, url, link_options)
110
- end
111
-
112
- wrap_tag ? content_tag(wrap_tag, link, :class => (css_class if css_class.present?)) : link
113
- end
114
-
115
- def active_link_to_class(url, options = {})
116
- if is_active_link?(url, options[:active])
117
- options[:class_active] || 'active'
118
- else
119
- options[:class_inactive] || ''
120
- end
121
- end
122
-
123
- def is_active_link?(url, condition = nil)
124
- url = url_for(url).sub(/\?.*/, '') # ignore GET params
125
- case condition
126
- when :inclusive, nil
127
- !request.fullpath.match(/^#{Regexp.escape(url).chomp('/')}(\/.*|\?.*)?$/).blank?
128
- when :exclusive
129
- !request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
130
- when Regexp
131
- !request.fullpath.match(condition).blank?
132
- when Array
133
- controllers = [*condition[0]]
134
- actions = [*condition[1]]
135
- (controllers.blank? || controllers.member?(params[:controller])) &&
136
- (actions.blank? || actions.member?(params[:action]))
137
- when TrueClass
138
- true
139
- when FalseClass
140
- false
141
- end
142
- end
143
-
4
+ require 'action_view'
5
+ require 'active_support/core_ext/object'
6
+ include ActionView::Helpers::AssetTagHelper
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::UrlHelper
9
+
10
+ require 'helper_methods/bootstrap'
11
+ require 'helper_methods/flash_messages'
12
+ require 'helper_methods/gravatar'
13
+ require 'helper_methods/mobile'
14
+ require 'helper_methods/qr_code'
15
+ require 'helper_methods/youtube'
144
16
  end
145
17
 
146
- ActionView::Base.send :include, HelperMethods
18
+ ActionView::Base.send :include, HelperMethods
@@ -0,0 +1,33 @@
1
+ module HelperMethods
2
+
3
+ def bootstrap_icon(name:, text: nil, config: :default)
4
+ icon = content_tag(:span, nil, class: "glyphicon glyphicon-#{name}")
5
+ label = content_tag(:span, text, class: "glyphicon-text")
6
+
7
+ opts = {
8
+ default: "#{icon}#{(label if text)}",
9
+ text_first: "#{(label if text)}#{icon}"
10
+ }
11
+
12
+ opts[config].html_safe
13
+ end
14
+
15
+ def bootstrap_label(text:, style: :default)
16
+
17
+ labels = {
18
+ default: 'label-default',
19
+ primary: 'label-primary',
20
+ success: 'label-success',
21
+ info: 'label-info',
22
+ warning: 'label-warning',
23
+ danger: 'label-danger'
24
+ }
25
+
26
+ content_tag :span, text, class: "label #{labels[style]}".html_safe
27
+ end
28
+
29
+ def bootstrap_badge(text:, style:'')
30
+ content_tag(:span, text, class: "badge #{style}").html_safe
31
+ end
32
+
33
+ end
@@ -0,0 +1,29 @@
1
+ module HelperMethods
2
+
3
+ def error_messages_for(resource, style = 'danger')
4
+ if resource.errors.any?
5
+ content_tag :div, class: "alert alert-#{style} alert-dismissable" do
6
+ content_tag :ol do
7
+ resource.errors.collect do |key, value|
8
+ content_tag :li, value
9
+ end.join.html_safe
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def flash_messages
16
+ if flash.any?
17
+ content_tag :div, class: "alert alert-success alert-dismissable" do
18
+ content_tag :ul do
19
+ flash.collect do |key, value|
20
+ unless [true, false, nil].include?(value)
21
+ content_tag :li, value
22
+ end
23
+ end.join.html_safe
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,8 @@
1
+ module HelperMethods
2
+
3
+ def gravatar(email:, html_options: {})
4
+ email = Digest::MD5.hexdigest(email)
5
+ image_tag "http://www.gravatar.com/avatar/#{email}?size=48", html_options
6
+ end
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ module HelperMethods
2
+
3
+ def mobile_device?
4
+ request.user_agent =~ /Mobile|webOS/
5
+ end
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ module HelperMethods
2
+
3
+ def qr_code_for(data:, size:)
4
+ url = 'https://chart.googleapis.com/chart'
5
+ params = { chs: size, cht: 'qr', chl: data }.to_query
6
+ image_tag("#{url}?#{params}")
7
+ end
8
+
9
+ end
@@ -1,3 +1,3 @@
1
1
  module HelperMethods
2
- VERSION = "0.0.20"
3
- end
2
+ VERSION = '1.0.0.rc1'
3
+ end
@@ -0,0 +1,11 @@
1
+ module HelperMethods
2
+
3
+ def youtube_video(id:, width: 580, height: 420)
4
+ content_tag :iframe, nil, height: height, width: width, src: "http://www.youtube.com/embed/#{id}", allowfullscreen: true
5
+ end
6
+
7
+ def youtube_link(id:, html_options: {})
8
+ link_to "www.youtube.com/watch?v=#{id}", "http://www.youtube.com/watch?v=#{id}", html_options
9
+ end
10
+
11
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelperMethods do
4
+ describe '.bootstrap_icon' do
5
+
6
+ before do
7
+ @icon_only = bootstrap_icon(name: 'search')
8
+ @icon_with_text = bootstrap_icon(name: 'search', text: 'Search')
9
+ @icon_with_text_first = bootstrap_icon(name: 'search', text: 'Search', config: :text_first)
10
+ end
11
+
12
+ it { expect(@icon_only).to eq('<span class="glyphicon glyphicon-search"></span>') }
13
+ it { expect(@icon_with_text).to eq('<span class="glyphicon glyphicon-search"></span><span class="glyphicon-text">Search</span>') }
14
+ it { expect(@icon_with_text_first).to eq('<span class="glyphicon-text">Search</span><span class="glyphicon glyphicon-search"></span>') }
15
+ end
16
+
17
+ describe '.bootstrap_label' do
18
+ before do
19
+ @default_label = bootstrap_label(text: 'Hello')
20
+ @warning_label = bootstrap_label(text: 'Hello', style: :warning)
21
+ end
22
+
23
+ it { expect(@default_label).to eq('<span class="label label-default">Hello</span>') }
24
+ it { expect(@warning_label).to eq('<span class="label label-warning">Hello</span>') }
25
+ end
26
+
27
+ describe '.bootstrap_badge' do
28
+ before do
29
+ @default_badge = bootstrap_badge(text: '42')
30
+ @pull_right_badge = bootstrap_badge(text: '42', style: 'pull-right')
31
+ end
32
+
33
+ it { expect(@default_badge).to eq('<span class="badge ">42</span>') }
34
+ it { expect(@pull_right_badge).to eq('<span class="badge pull-right">42</span>') }
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelperMethods do
4
+ describe '.gravatar' do
5
+ before do
6
+ @gravatar = gravatar(email: 'franciscomxs@gmail.com')
7
+ end
8
+
9
+ it { expect(@gravatar).to eq('<img alt="Ed51f087eafad0d6e5fd5c55be777330?size=48" src="http://www.gravatar.com/avatar/ed51f087eafad0d6e5fd5c55be777330?size=48" />') }
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelperMethods do
4
+ describe '.qrcode_for' do
5
+ before do
6
+ @qrcode = qr_code_for(data: 'http://mibuz.com.br', size: 80)
7
+ end
8
+
9
+ it { expect(@qrcode).to eq('<img alt="Chart?chl=http%3a%2f%2fmibuz.com" src="https://chart.googleapis.com/chart?chl=http%3A%2F%2Fmibuz.com.br&amp;chs=80&amp;cht=qr" />') }
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe HelperMethods do
4
+ describe '.youtube_video' do
5
+ before do
6
+ @video = youtube_video(id: 's-NtkVZsGQc')
7
+ @large_video = youtube_video(id: 's-NtkVZsGQc', width: 720, height: 360)
8
+ end
9
+
10
+ it { expect(@video).to eq('<iframe allowfullscreen="allowfullscreen" height="420" src="http://www.youtube.com/embed/s-NtkVZsGQc" width="580"></iframe>') }
11
+ it { expect(@large_video).to eq('<iframe allowfullscreen="allowfullscreen" height="360" src="http://www.youtube.com/embed/s-NtkVZsGQc" width="720"></iframe>') }
12
+ end
13
+
14
+ describe '.youtube_link' do
15
+ before do
16
+ @video = youtube_link(id: 's-NtkVZsGQc')
17
+ end
18
+
19
+ it { expect(@video).to eq('<a href="http://www.youtube.com/watch?v=s-NtkVZsGQc">www.youtube.com/watch?v=s-NtkVZsGQc</a>') }
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'rspec'
2
+ require 'helper_methods'
3
+ include HelperMethods
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+ end
metadata CHANGED
@@ -1,30 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helper_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Martins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-17 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
13
55
  description: A small collection of simple methods
14
- email:
15
- - franciscomxs@gmail.com
56
+ email: franciscomxs@gmail.com
16
57
  executables: []
17
58
  extensions: []
18
59
  extra_rdoc_files: []
19
60
  files:
20
- - .gitignore
61
+ - ".gitignore"
62
+ - ".rspec"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
21
65
  - Gemfile
22
66
  - LICENSE.txt
23
67
  - README.md
24
68
  - Rakefile
25
69
  - helper_methods.gemspec
26
70
  - lib/helper_methods.rb
71
+ - lib/helper_methods/bootstrap.rb
72
+ - lib/helper_methods/flash_messages.rb
73
+ - lib/helper_methods/gravatar.rb
74
+ - lib/helper_methods/mobile.rb
75
+ - lib/helper_methods/qr_code.rb
27
76
  - lib/helper_methods/version.rb
77
+ - lib/helper_methods/youtube.rb
78
+ - spec/helper_methods/bootstrap_spec.rb
79
+ - spec/helper_methods/gravatar_spec.rb
80
+ - spec/helper_methods/qr_code_spec.rb
81
+ - spec/helper_methods/youtube_spec.rb
82
+ - spec/spec_helper.rb
28
83
  homepage: https://github.com/franciscomxs/helper_methods
29
84
  licenses:
30
85
  - MIT
@@ -35,18 +90,23 @@ require_paths:
35
90
  - lib
36
91
  required_ruby_version: !ruby/object:Gem::Requirement
37
92
  requirements:
38
- - - '>='
93
+ - - ">="
39
94
  - !ruby/object:Gem::Version
40
95
  version: '0'
41
96
  required_rubygems_version: !ruby/object:Gem::Requirement
42
97
  requirements:
43
- - - '>='
98
+ - - ">"
44
99
  - !ruby/object:Gem::Version
45
- version: '0'
100
+ version: 1.3.1
46
101
  requirements: []
47
102
  rubyforge_project:
48
- rubygems_version: 2.1.5
103
+ rubygems_version: 2.2.2
49
104
  signing_key:
50
105
  specification_version: 4
51
106
  summary: Helper methods that helps you to DRY
52
- test_files: []
107
+ test_files:
108
+ - spec/helper_methods/bootstrap_spec.rb
109
+ - spec/helper_methods/gravatar_spec.rb
110
+ - spec/helper_methods/qr_code_spec.rb
111
+ - spec/helper_methods/youtube_spec.rb
112
+ - spec/spec_helper.rb