html_slice 0.2.5 → 0.2.7
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/lib/html_slice/rails.rb +25 -0
- data/lib/html_slice/version.rb +1 -1
- data/lib/html_slice.rb +33 -18
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a79c8996b475562f9dda72bed310544562e53a291e1cee0d539a3c3280665fb6
|
|
4
|
+
data.tar.gz: b17fe1d34ce2faa82441654496e38d92b28e001ef079b74d6b8e1d481de5fd85
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87e6f121b744b3c39b9150b582079455b682e3607190042bc75b987ff4d3a692614a408ed493a4ef1a40fdf008a3548a21e3220c2ab4962516793daa975b59d3
|
|
7
|
+
data.tar.gz: 1db761b53c2bd886cc644fb192a23f6d6e0816683f3527320044b739acba2868a5cfccb7503f4f9ea2e365fa5d7e5ed175e996aabadd743793d34ec621928346
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module HtmlSlice
|
|
4
|
+
module Rails
|
|
5
|
+
def self.included(base)
|
|
6
|
+
base.class_eval do
|
|
7
|
+
include ActionView::RecordIdentifier
|
|
8
|
+
include ActionView::Helpers::FormHelper
|
|
9
|
+
include ActionView::Helpers::FormOptionsHelper
|
|
10
|
+
include ActionView::Helpers::TranslationHelper
|
|
11
|
+
include ActionView::Helpers::UrlHelper
|
|
12
|
+
include ::Rails.application.routes.url_helpers
|
|
13
|
+
include HtmlSlice
|
|
14
|
+
|
|
15
|
+
def controller
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def slice(slice_id = HtmlSlice::DEFAULT_SLICE, &block)
|
|
20
|
+
html_slice(slice_id, &block).html_safe
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/html_slice/version.rb
CHANGED
data/lib/html_slice.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "html_slice/rails"
|
|
3
4
|
require_relative "html_slice/version"
|
|
4
5
|
require "cgi"
|
|
5
6
|
|
|
@@ -7,7 +8,7 @@ module HtmlSlice
|
|
|
7
8
|
class Error < StandardError; end
|
|
8
9
|
|
|
9
10
|
TAGS = %i[
|
|
10
|
-
div title embed meta br a em b i ul ol li img table tbody thead tr th td
|
|
11
|
+
div title embed meta br a em b i ul ol li img table tbody thead tr th td strong
|
|
11
12
|
form input button link h1 h2 h3 h4 h5 h6 hr span label iframe template main
|
|
12
13
|
footer aside source section small nav area
|
|
13
14
|
].freeze
|
|
@@ -21,9 +22,25 @@ module HtmlSlice
|
|
|
21
22
|
].freeze
|
|
22
23
|
|
|
23
24
|
DEFAULT_SLICE = :default
|
|
24
|
-
ATTRIBUTE_CACHE = {}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
ATTRIBUTE_KEY_CACHE = {}
|
|
27
|
+
|
|
28
|
+
STR = {
|
|
29
|
+
empty: "",
|
|
30
|
+
space: " ",
|
|
31
|
+
underline: "_",
|
|
32
|
+
dash: "-",
|
|
33
|
+
attr_equal: "='",
|
|
34
|
+
single_quote: "'",
|
|
35
|
+
doctype_html: "<!DOCTYPE html><html>",
|
|
36
|
+
end_html: "</html>",
|
|
37
|
+
gt: ">",
|
|
38
|
+
gt_slash: "/>",
|
|
39
|
+
lt: "<",
|
|
40
|
+
lt_slash: "</",
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
def self.slice(slice_id = DEFAULT_SLICE, wrap: [STR[:empty], STR[:empty]], &block)
|
|
27
44
|
@class ||= Class.new { include HtmlSlice }.new
|
|
28
45
|
@class.html_slice(slice_id, wrap: wrap, &block)
|
|
29
46
|
end
|
|
@@ -34,15 +51,15 @@ module HtmlSlice
|
|
|
34
51
|
end
|
|
35
52
|
|
|
36
53
|
def html_layout(slice_id = DEFAULT_SLICE, &block)
|
|
37
|
-
html_slice(slice_id, wrap: [
|
|
54
|
+
html_slice(slice_id, wrap: [STR[:doctype_html], STR[:end_html]], &block)
|
|
38
55
|
end
|
|
39
56
|
|
|
40
|
-
def html_slice(slice_id = DEFAULT_SLICE, wrap: [
|
|
57
|
+
def html_slice(slice_id = DEFAULT_SLICE, wrap: [STR[:empty], STR[:empty]], &block)
|
|
41
58
|
@html_slice_current_id = slice_id
|
|
42
59
|
@html_slice ||= {}
|
|
43
60
|
|
|
44
61
|
if block_given?
|
|
45
|
-
buffer = +
|
|
62
|
+
buffer = +STR[:empty]
|
|
46
63
|
buffer << wrap[0]
|
|
47
64
|
@html_slice[slice_id] = buffer
|
|
48
65
|
instance_eval(&block)
|
|
@@ -80,7 +97,7 @@ module HtmlSlice
|
|
|
80
97
|
private
|
|
81
98
|
|
|
82
99
|
def parse_args(args, escape: true)
|
|
83
|
-
content =
|
|
100
|
+
content = STR[:empty]
|
|
84
101
|
attributes = {}
|
|
85
102
|
first = args[0]
|
|
86
103
|
if first.is_a?(String)
|
|
@@ -95,27 +112,25 @@ module HtmlSlice
|
|
|
95
112
|
def render_tag(name_str, tag_sym, content, attributes, &block)
|
|
96
113
|
@html_slice ||= {}
|
|
97
114
|
@html_slice_current_id ||= DEFAULT_SLICE
|
|
98
|
-
@html_slice[@html_slice_current_id] ||= +
|
|
115
|
+
@html_slice[@html_slice_current_id] ||= +STR[:empty]
|
|
99
116
|
buffer = @html_slice[@html_slice_current_id]
|
|
100
117
|
|
|
101
|
-
buffer <<
|
|
118
|
+
buffer << STR[:lt] << name_str
|
|
102
119
|
unless attributes.empty?
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
end.join
|
|
120
|
+
attributes.each do |key, value|
|
|
121
|
+
cached_key = ATTRIBUTE_KEY_CACHE[key] ||= key.to_s.tr(STR[:underline], STR[:dash]).freeze
|
|
122
|
+
buffer << STR[:space] << cached_key << STR[:attr_equal] << value.to_s << STR[:single_quote]
|
|
107
123
|
end
|
|
108
|
-
buffer << attributes_string
|
|
109
124
|
end
|
|
110
125
|
|
|
111
126
|
if block_given?
|
|
112
|
-
buffer <<
|
|
127
|
+
buffer << STR[:gt]
|
|
113
128
|
instance_exec(&block)
|
|
114
|
-
buffer <<
|
|
129
|
+
buffer << [STR[:lt_slash], name_str, STR[:gt]].join
|
|
115
130
|
elsif content.empty? && EMPTY_TAGS.include?(tag_sym)
|
|
116
|
-
buffer <<
|
|
131
|
+
buffer << STR[:gt_slash]
|
|
117
132
|
else
|
|
118
|
-
buffer <<
|
|
133
|
+
buffer << STR[:gt] << content << [STR[:lt_slash], name_str, STR[:gt]].join
|
|
119
134
|
end
|
|
120
135
|
end
|
|
121
136
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: html_slice
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- henrique-ft
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Enable Ruby classes the ability to generate reusable pieces of html
|
|
14
13
|
email:
|
|
@@ -18,13 +17,12 @@ extensions: []
|
|
|
18
17
|
extra_rdoc_files: []
|
|
19
18
|
files:
|
|
20
19
|
- lib/html_slice.rb
|
|
20
|
+
- lib/html_slice/rails.rb
|
|
21
21
|
- lib/html_slice/version.rb
|
|
22
|
-
homepage:
|
|
23
22
|
licenses: []
|
|
24
23
|
metadata:
|
|
25
24
|
source_code_uri: https://github.com/henrique-ft/html_slice
|
|
26
25
|
changelog_uri: https://github.com/henrique-ft/html_slice/blob/master/CHANGELOG.md
|
|
27
|
-
post_install_message:
|
|
28
26
|
rdoc_options: []
|
|
29
27
|
require_paths:
|
|
30
28
|
- lib
|
|
@@ -39,8 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
39
37
|
- !ruby/object:Gem::Version
|
|
40
38
|
version: '0'
|
|
41
39
|
requirements: []
|
|
42
|
-
rubygems_version:
|
|
43
|
-
signing_key:
|
|
40
|
+
rubygems_version: 4.0.6
|
|
44
41
|
specification_version: 4
|
|
45
42
|
summary: Enable Ruby classes the ability to generate reusable pieces of html
|
|
46
43
|
test_files: []
|