lotus-helpers 0.2.5 → 0.2.6
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 +4 -4
- data/CHANGELOG.md +35 -0
- data/LICENSE.md +1 -1
- data/README.md +1 -1
- data/lib/lotus/helpers/form_helper/form_builder.rb +26 -14
- data/lib/lotus/helpers/html_helper.rb +17 -2
- data/lib/lotus/helpers/html_helper/html_builder.rb +40 -0
- data/lib/lotus/helpers/html_helper/html_fragment.rb +45 -0
- data/lib/lotus/helpers/routing_helper.rb +3 -3
- data/lib/lotus/helpers/version.rb +1 -1
- data/lotus-helpers.gemspec +2 -2
- metadata +7 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d83c162dc06d805a23d1266f8898ef9dbfaf1527
|
4
|
+
data.tar.gz: d2c072bfbcb73f392862e8614f3ac1c7ecf739a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46166d61c7fe8ae7c7b13cbc98c55ae830f836970f93247559c0045dcca7827fd71ea32fbac75482a8c9b362ae56e6e84f9e75359634f5c747b446df390e83df
|
7
|
+
data.tar.gz: 9b932b774eb95ed64c2e6c4779cfaf37a4861cce5121f55c9b29114809bfb748b43dcfa36ffe13dea19d59a3ff80f175720c57f9070cf2ff865c1af55720367b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Lotus::Helpers
|
2
|
+
View helpers for Ruby web applications
|
3
|
+
|
4
|
+
## v0.2.6 - 2016-01-12
|
5
|
+
### Added
|
6
|
+
- [Cam Huynh] Added support for HTML helper (`#html`) block syntax (eg. `html { div('hello') }`)
|
7
|
+
- [Shin-ichi Ueda] Added support for `<dd>` HTML tag
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
- [Rodrigo Panachi] Don't generate CSRF token hidden input for forms with `GET` method
|
11
|
+
|
12
|
+
## v0.2.5 - 2015-09-30
|
13
|
+
### Added
|
14
|
+
- [Leonardo Saraiva] Improved support for HTML content in `#link_to` helper. It now accepts blocks to build markup inside an anchor tag.
|
15
|
+
- [José Mota] Added `#text` to the form builder
|
16
|
+
- [Alex Wochna] Added `#number_field` to the form builder
|
17
|
+
- [Scott Le] Added `#text_area` to the form builder
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- [Pascal Betz] Ensure boolean attributes in HTML forms to not be printed if their value is `nil` (eg. avoid to print `disabled=""`).
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
- [Luca Guidi] Form `#label` helper outputs capitalized strings, instead of titleized (eg. `"Remember me"` instead of `"Remember Me"`).
|
24
|
+
|
25
|
+
## v0.2.0 - 2015-06-23
|
26
|
+
### Added
|
27
|
+
- [Luca Guidi] Introduced `Lotus::Helpers::FormHelper`. HTML5 form generator (`#form_for`).
|
28
|
+
- [Tom Kadwill & Luca Guidi] Introduced `Lotus::Helpers::NumberFormattingHelper`. Format numbers (`#format_number`).
|
29
|
+
- [Tom Kadwill] Introduced `Lotus::Helpers::LinkToHelper`. Link helper (`#link_to`).
|
30
|
+
|
31
|
+
## v0.1.0 - 2015-03-23
|
32
|
+
### Added
|
33
|
+
- [Luca Guidi] Introduced `Lotus::Helpers::RoutingHelper`. It exposes `#routes` in views for compatibility with Lotus (`lotusrb` gem)
|
34
|
+
- [Alfonso Uceda Pompa] Introduced `Lotus::Helpers::EscapeHelper`. It implements OWASP/ESAPI suggestions for HTML, HTML attribute and URL escape helpers.
|
35
|
+
- [Luca Guidi] Introduced `Lotus::Helpers::HtmlHelper`. It allows to generate complex HTML5 markup with Ruby.
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,12 @@ module Lotus
|
|
18
18
|
# @api private
|
19
19
|
BROWSER_METHODS = ['GET', 'POST'].freeze
|
20
20
|
|
21
|
+
# Set of HTTP methods that should NOT generate CSRF token
|
22
|
+
#
|
23
|
+
# @since 0.2.0
|
24
|
+
# @api private
|
25
|
+
EXCLUDED_CSRF_METHODS = ['GET'].freeze
|
26
|
+
|
21
27
|
# Checked attribute value
|
22
28
|
#
|
23
29
|
# @since 0.2.0
|
@@ -106,15 +112,16 @@ module Lotus
|
|
106
112
|
|
107
113
|
# Nested form
|
108
114
|
if @context.nil? && attributes.is_a?(Values)
|
109
|
-
@values
|
110
|
-
@attributes
|
111
|
-
@name
|
115
|
+
@values = attributes
|
116
|
+
@attributes = {}
|
117
|
+
@name = form
|
112
118
|
else
|
113
|
-
@form
|
114
|
-
@name
|
115
|
-
@values
|
116
|
-
@attributes
|
117
|
-
@
|
119
|
+
@form = form
|
120
|
+
@name = form.name
|
121
|
+
@values = Values.new(form.values, @context.params)
|
122
|
+
@attributes = attributes
|
123
|
+
@verb_method = verb_method
|
124
|
+
@csrf_token = csrf_token
|
118
125
|
end
|
119
126
|
end
|
120
127
|
|
@@ -792,22 +799,27 @@ module Lotus
|
|
792
799
|
# @api private
|
793
800
|
# @since 0.2.0
|
794
801
|
def _method_override!
|
795
|
-
|
796
|
-
|
797
|
-
if BROWSER_METHODS.include?(verb)
|
798
|
-
@attributes[:method] = verb
|
802
|
+
if BROWSER_METHODS.include?(@verb_method)
|
803
|
+
@attributes[:method] = @verb_method
|
799
804
|
else
|
800
805
|
@attributes[:method] = DEFAULT_METHOD
|
801
|
-
@verb =
|
806
|
+
@verb = @verb_method
|
802
807
|
end
|
803
808
|
end
|
804
809
|
|
810
|
+
# Return the method from attributes
|
811
|
+
#
|
812
|
+
# @api private
|
813
|
+
def verb_method
|
814
|
+
(@attributes.fetch(:method) { DEFAULT_METHOD }).to_s.upcase
|
815
|
+
end
|
816
|
+
|
805
817
|
# Return CSRF Protection token from view context
|
806
818
|
#
|
807
819
|
# @api private
|
808
820
|
# @since 0.2.0
|
809
821
|
def csrf_token
|
810
|
-
@context.csrf_token if @context.respond_to?(:csrf_token)
|
822
|
+
@context.csrf_token if @context.respond_to?(:csrf_token) && !EXCLUDED_CSRF_METHODS.include?(@verb_method)
|
811
823
|
end
|
812
824
|
|
813
825
|
# Return a set of default HTML attributes
|
@@ -65,6 +65,15 @@ module Lotus
|
|
65
65
|
# # hello
|
66
66
|
# #</div>
|
67
67
|
#
|
68
|
+
# # 8
|
69
|
+
# html do
|
70
|
+
# li 'Hello'
|
71
|
+
# li 'Lotus'
|
72
|
+
# end
|
73
|
+
# # =>
|
74
|
+
# #<li>Hello</li>
|
75
|
+
# #<li>Lotus</li>
|
76
|
+
#
|
68
77
|
#
|
69
78
|
#
|
70
79
|
# @example Complex markup
|
@@ -178,14 +187,20 @@ module Lotus
|
|
178
187
|
private
|
179
188
|
# Instantiate an HTML builder
|
180
189
|
#
|
190
|
+
# @param blk [Proc,Lotus::Helpers::HtmlHelper::HtmlBuilder,NilClass] the optional content block
|
191
|
+
#
|
181
192
|
# @return [Lotus::Helpers::HtmlHelper::HtmlBuilder] the HTML builder
|
182
193
|
#
|
183
194
|
# @since 0.1.0
|
184
195
|
#
|
185
196
|
# @see Lotus::Helpers::HtmlHelper
|
186
197
|
# @see Lotus::Helpers::HtmlHelper::HtmlBuilder
|
187
|
-
def html
|
188
|
-
|
198
|
+
def html(&blk)
|
199
|
+
if block_given?
|
200
|
+
HtmlBuilder.new.fragment(&blk)
|
201
|
+
else
|
202
|
+
HtmlBuilder.new
|
203
|
+
end
|
189
204
|
end
|
190
205
|
end
|
191
206
|
end
|
@@ -3,6 +3,7 @@ require 'lotus/utils/class_attribute'
|
|
3
3
|
require 'lotus/utils/escape'
|
4
4
|
require 'lotus/helpers/html_helper/empty_html_node'
|
5
5
|
require 'lotus/helpers/html_helper/html_node'
|
6
|
+
require 'lotus/helpers/html_helper/html_fragment'
|
6
7
|
require 'lotus/helpers/html_helper/text_node'
|
7
8
|
|
8
9
|
module Lotus
|
@@ -45,6 +46,7 @@ module Lotus
|
|
45
46
|
'div',
|
46
47
|
'dl',
|
47
48
|
'dt',
|
49
|
+
'dd',
|
48
50
|
'em',
|
49
51
|
'fieldset',
|
50
52
|
'figcaption',
|
@@ -231,6 +233,32 @@ module Lotus
|
|
231
233
|
self
|
232
234
|
end
|
233
235
|
|
236
|
+
# Define a HTML fragment
|
237
|
+
#
|
238
|
+
# @param blk [Proc] the optional nested content espressed as a block
|
239
|
+
#
|
240
|
+
# @return [self]
|
241
|
+
#
|
242
|
+
# @since 0.2.6
|
243
|
+
# @api public
|
244
|
+
#
|
245
|
+
# @see Lotus::Helpers::HtmlHelper
|
246
|
+
#
|
247
|
+
# @example
|
248
|
+
# html.fragment('Lotus') # => Lotus
|
249
|
+
#
|
250
|
+
# html do
|
251
|
+
# p 'hello'
|
252
|
+
# p 'lotus'
|
253
|
+
# end
|
254
|
+
# # =>
|
255
|
+
# <p>hello</p>
|
256
|
+
# <p>lotus</p>
|
257
|
+
def fragment(&blk)
|
258
|
+
@nodes << HtmlFragment.new(&blk)
|
259
|
+
self
|
260
|
+
end
|
261
|
+
|
234
262
|
# Defines a custom empty tag
|
235
263
|
#
|
236
264
|
# @param name [Symbol,String] the name of the tag
|
@@ -296,6 +324,18 @@ module Lotus
|
|
296
324
|
Utils::Escape::SafeString.new(@nodes.map(&:to_s).join(NEWLINE))
|
297
325
|
end
|
298
326
|
|
327
|
+
# Encode the content with the given character encoding
|
328
|
+
#
|
329
|
+
# @param encoding [Encoding,String] the encoding or its string representation
|
330
|
+
#
|
331
|
+
# @return [String] the encoded string
|
332
|
+
#
|
333
|
+
# @since 0.2.5
|
334
|
+
# @api private
|
335
|
+
def encode(encoding)
|
336
|
+
to_s.encode(encoding)
|
337
|
+
end
|
338
|
+
|
299
339
|
# Check if there are nested nodes
|
300
340
|
#
|
301
341
|
# @return [TrueClass,FalseClass] the result of the check
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Lotus
|
2
|
+
module Helpers
|
3
|
+
module HtmlHelper
|
4
|
+
# HTML Fragment
|
5
|
+
#
|
6
|
+
# @since 0.2.6
|
7
|
+
# @api private
|
8
|
+
#
|
9
|
+
# @see Lotus::Helpers::HtmlHelper::HtmlFragment
|
10
|
+
class HtmlFragment
|
11
|
+
# Initialize a HTML Fragment
|
12
|
+
#
|
13
|
+
# @param blk [Proc,Lotus::Helpers::HtmlHelper::HtmlBuilder,NilClass] the content block
|
14
|
+
#
|
15
|
+
# @return [Lotus::Helpers::HtmlHelper::HtmlFragment]
|
16
|
+
def initialize(&blk)
|
17
|
+
@builder = HtmlBuilder.new
|
18
|
+
@blk = blk
|
19
|
+
end
|
20
|
+
|
21
|
+
# Resolve and return the output
|
22
|
+
#
|
23
|
+
# @return [String] the output
|
24
|
+
#
|
25
|
+
# @since 0.2.6
|
26
|
+
# @api private
|
27
|
+
#
|
28
|
+
# @see Lotus::Helpers::HtmlHelper::EmptyHtmlNode#to_s
|
29
|
+
def to_s
|
30
|
+
content.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def content
|
34
|
+
result = @builder.resolve(&@blk)
|
35
|
+
|
36
|
+
if @builder.nested?
|
37
|
+
@builder.to_s
|
38
|
+
else
|
39
|
+
"#{ Utils::Escape.html(result) }"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -28,10 +28,10 @@ module Lotus
|
|
28
28
|
# module Web::Views::Home
|
29
29
|
# class Index
|
30
30
|
# include Web::View
|
31
|
-
# end
|
32
31
|
#
|
33
|
-
#
|
34
|
-
#
|
32
|
+
# def link_to_home
|
33
|
+
# %(<a href="#{ routes.home_path }">Home</a>)
|
34
|
+
# end
|
35
35
|
# end
|
36
36
|
# end
|
37
37
|
#
|
data/lotus-helpers.gemspec
CHANGED
@@ -13,13 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'http://lotusrb.org'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files -- lib/* LICENSE.md README.md lotus-helpers.gemspec`.split($/)
|
16
|
+
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md lotus-helpers.gemspec`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
spec.required_ruby_version = '>= 2.0.0'
|
21
21
|
|
22
|
-
spec.add_dependency 'lotus-utils', '~> 0.
|
22
|
+
spec.add_dependency 'lotus-utils', '~> 0.6'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: lotus-utils
|
@@ -18,20 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.5.2
|
21
|
+
version: '0.6'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
requirements:
|
29
26
|
- - "~>"
|
30
27
|
- !ruby/object:Gem::Version
|
31
|
-
version: '0.
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.5.2
|
28
|
+
version: '0.6'
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: bundler
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +77,7 @@ executables: []
|
|
83
77
|
extensions: []
|
84
78
|
extra_rdoc_files: []
|
85
79
|
files:
|
80
|
+
- CHANGELOG.md
|
86
81
|
- LICENSE.md
|
87
82
|
- README.md
|
88
83
|
- lib/lotus-helpers.rb
|
@@ -95,6 +90,7 @@ files:
|
|
95
90
|
- lib/lotus/helpers/html_helper.rb
|
96
91
|
- lib/lotus/helpers/html_helper/empty_html_node.rb
|
97
92
|
- lib/lotus/helpers/html_helper/html_builder.rb
|
93
|
+
- lib/lotus/helpers/html_helper/html_fragment.rb
|
98
94
|
- lib/lotus/helpers/html_helper/html_node.rb
|
99
95
|
- lib/lotus/helpers/html_helper/text_node.rb
|
100
96
|
- lib/lotus/helpers/link_to_helper.rb
|
@@ -122,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
118
|
version: '0'
|
123
119
|
requirements: []
|
124
120
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.1
|
126
122
|
signing_key:
|
127
123
|
specification_version: 4
|
128
124
|
summary: Lotus helpers
|