rails_view_helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # RailsViewHelpers
2
+
3
+ [API documentation](http://rubydoc.info/gems/rails_view_helpers/frames/file/README.md)
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsViewHelpers'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,60 @@
1
+ # Utililty methods used by Bootstrap::*Helper classes
2
+ module RailsViewHelpers::CommonHelper
3
+ ArgumentError = Class.new(::ArgumentError)
4
+
5
+ # Returns a new Hash with:
6
+ # * keys converted to Symbols
7
+ # * the +:class+ key has its value converted to an Array of String
8
+ # @example
9
+ # canonicalize_options("id" => "ID", "class" => "CLASS") # => {:id=>"ID", :class=>["CLASS"]}
10
+ # canonicalize_options(:class => 'one two') # => {:class=>["one", "two"]}
11
+ # canonicalize_options("class" => [:one, 2]) # => {:class=>["one", "2"]}
12
+ # @param [Hash] hash typically an +options+ param to a method call
13
+ # @raise [ArgumentError] if _hash_ is not a Hash
14
+ # @return [Hash]
15
+ def canonicalize_options(hash)
16
+ raise ArgumentError.new("expected a Hash, got #{hash.inspect}") unless hash.is_a?(Hash)
17
+
18
+ hash.symbolize_keys.tap do |h|
19
+ h[:class] = arrayify_and_stringify_elements(h[:class])
20
+ end
21
+ end
22
+
23
+ # Returns a new Array of String from _arg_.
24
+ # @example
25
+ # arrayify_and_stringify_elements(nil) #=> []
26
+ # arrayify_and_stringify_elements('foo') #=> ["foo"]
27
+ # arrayify_and_stringify_elements('foo bar') #=> ["foo", "bar"]
28
+ # arrayify_and_stringify_elements([:foo, 'bar']) #=> ["foo", "bar"]
29
+ # @param [String, Array] arg
30
+ # @return [Array of String]
31
+ def arrayify_and_stringify_elements(arg)
32
+ return false if arg == false
33
+
34
+ case
35
+ when arg.blank? then []
36
+ when arg.is_a?(Array) then arg
37
+ else arg.to_s.strip.split(/\s/)
38
+ end.map(&:to_s)
39
+ end
40
+
41
+ # Returns new (canonicalized) Hash where :class value includes _klasses_.
42
+ #
43
+ # @example
44
+ # ensure_class({class: []}, 'foo') #=> {class: 'foo'}
45
+ # ensure_class({class: ['bar'], id: 'my-id'}, ['foo', 'foo2']) #=> {:class=>["bar", "foo", "foo2"], :id=>"my-id"}
46
+ # @param [Hash] hash
47
+ # @param [String, Array] klasses one or more classes to add to the +:class+ key of _hash_
48
+ # @return [Hash]
49
+ def ensure_class(hash, klasses)
50
+ canonicalize_options(hash)
51
+
52
+ hash.dup.tap do |h|
53
+ Array(klasses).map(&:to_s).each do |k|
54
+ h[:class] << k unless h[:class].include?(k)
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ end
@@ -0,0 +1,62 @@
1
+ module RailsViewHelpers
2
+
3
+ module HtmlHelper
4
+
5
+ # Includes controller and action name as data attributes.
6
+ #
7
+ # @example
8
+ # body_tag() #=> <body data-action='index' data-controller='home'>
9
+ #
10
+ # body_tag(id: 'my-id', class: 'my-class') #=> <body class="my-class" data-action="index" data-controller="home" id="my-id">
11
+ def body_tag(options={}, &block)
12
+ options = canonicalize_options(options)
13
+ options.delete(:class) if options[:class].blank?
14
+ options[:data] ||= {}
15
+ options[:data][:controller] = controller.controller_name
16
+ options[:data][:action] = controller.action_name
17
+
18
+ content_tag(:body, options) do
19
+ yield
20
+ end
21
+ end
22
+
23
+ # Displays a check-mark (&#10004;) when _bln_ is +true+ else +nbsp+.
24
+ #
25
+ # @example
26
+ # bln(true) #=> "&#10004;" (check mark)
27
+ # bln(false) #=> "&nbsp;" (space)
28
+ # bln(true, 'Admin') #=> "Admin"
29
+ # bln(false, 'Admin', "not Admin") #=> "not Admin"
30
+ # @param bool [Boolean]
31
+ # @param true_string [String] the string to display if _bln_ is +true+. Caller is responsible for escaping and/or marking html_safe.
32
+ # @param false_string [String] the string to display if _bln_ is +false+. Caller is responsible for escaping and/or marking html_safe.
33
+ def bln(bool, true_string="&#10004;".html_safe, false_string=nbsp)
34
+ if bool
35
+ true_string
36
+ else
37
+ false_string
38
+ end
39
+ end
40
+
41
+ def td_bln(*args)
42
+ options = canonicalize_options(args.extract_options!)
43
+ options = ensure_class(options, 'c')
44
+
45
+ content_tag(:td, bln(*args), options)
46
+ end
47
+
48
+ # Returns one or more non-breaking spaces (&nbsp;) marked +html_safe+.
49
+ #
50
+ # @example
51
+ # nbsp #=> "&nbsp;"
52
+ # nbsp(3) #=> "&nbsp;&nbsp;&nbsp;"
53
+ #
54
+ # @param count [FixNum] the number of non-breaking spaces to return
55
+ # @return [String] that is html_safe
56
+ def nbsp(count=1)
57
+ ('&nbsp;' * count).html_safe
58
+ end
59
+
60
+ end
61
+
62
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ module RailsViewHelpers
2
+ class Engine < ::Rails::Engine
3
+ config.generators.integration_tool :rspec
4
+ config.generators.test_framework :rspec
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module RailsViewHelpers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "rails_view_helpers/engine"
2
+
3
+ module RailsViewHelpers
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_view_helpers do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,302 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_view_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Downey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: jquery-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: capybara
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-spork
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: coveralls
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sqlite3
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: haml
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: better_errors
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: binding_of_caller
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: redcarpet
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: yard
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: quiet_assets
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: thin
240
+ requirement: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ description:
255
+ email:
256
+ - steve.downtown@gmail.com
257
+ executables: []
258
+ extensions: []
259
+ extra_rdoc_files: []
260
+ files:
261
+ - app/helpers/rails_view_helpers/common_helper.rb
262
+ - app/helpers/rails_view_helpers/html_helper.rb
263
+ - config/routes.rb
264
+ - lib/rails_view_helpers/engine.rb
265
+ - lib/rails_view_helpers/version.rb
266
+ - lib/rails_view_helpers.rb
267
+ - lib/tasks/rails_view_helpers_tasks.rake
268
+ - MIT-LICENSE
269
+ - Rakefile
270
+ - README.md
271
+ homepage: https://github.com/stevedowney/rails_view_helpers
272
+ licenses: []
273
+ post_install_message:
274
+ rdoc_options: []
275
+ require_paths:
276
+ - lib
277
+ required_ruby_version: !ruby/object:Gem::Requirement
278
+ none: false
279
+ requirements:
280
+ - - ! '>='
281
+ - !ruby/object:Gem::Version
282
+ version: '0'
283
+ segments:
284
+ - 0
285
+ hash: -3460792648407326703
286
+ required_rubygems_version: !ruby/object:Gem::Requirement
287
+ none: false
288
+ requirements:
289
+ - - ! '>='
290
+ - !ruby/object:Gem::Version
291
+ version: '0'
292
+ segments:
293
+ - 0
294
+ hash: -3460792648407326703
295
+ requirements: []
296
+ rubyforge_project:
297
+ rubygems_version: 1.8.25
298
+ signing_key:
299
+ specification_version: 3
300
+ summary: Convenience methods for Rails views
301
+ test_files: []
302
+ has_rdoc: