inky-rb 1.3.7.3 → 1.4.2.0
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/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +4 -2
- data/README.md +1 -1
- data/gemfiles/rails_6.gemfile +5 -0
- data/inky.gemspec +6 -6
- data/lib/inky/component_factory.rb +21 -9
- data/lib/inky/configuration.rb +22 -1
- data/lib/inky/rails/template_handler.rb +7 -3
- data/lib/inky/rails/version.rb +1 -1
- data/lib/inky.rb +5 -2
- data/spec/_cases_output/button/no_link.inky +1 -0
- data/spec/_cases_output/button/with_expand_class.inky +4 -0
- data/spec/_cases_output/button/with_extra_attr.inky +3 -0
- data/spec/_cases_output/button/with_image.inky +3 -0
- data/spec/_cases_output/button/with_link.inky +3 -0
- data/spec/_cases_output/button/with_link_and_extra_attr.inky +3 -0
- data/spec/_cases_output/button/with_tricky_class.inky +22 -0
- data/spec/_cases_output/callout/basic.inky +1 -0
- data/spec/_cases_output/callout/with_attributes.inky +3 -0
- data/spec/_cases_output/general/empty_attributes.inky +6 -0
- data/spec/_cases_output/general/multiple_root.inky +2 -0
- data/spec/_cases_output/general/no_tag.inky +1 -0
- data/spec/_cases_output/general/root_within_text.inky +7 -0
- data/spec/_cases_output/general/void_html_elements.inky +6 -0
- data/spec/_cases_output/grid/columns.inky +2 -0
- data/spec/_cases_output/grid/container.inky +1 -0
- data/spec/_cases_output/grid/container_with_align.inky +1 -0
- data/spec/_cases_output/grid/row.inky +1 -0
- data/spec/_cases_output/grid/row_with_columns.inky +5 -0
- data/spec/_cases_output/h_line/basic.inky +1 -0
- data/spec/_cases_output/h_line/h_line.inky +2 -0
- data/spec/_cases_output/h_line/multiple.inky +3 -0
- data/spec/_cases_output/h_line/with_attr.inky +1 -0
- data/spec/_cases_output/menu/item.inky +1 -0
- data/spec/_cases_output/menu/menu.inky +2 -0
- data/spec/_cases_output/menu/menu_with_align.inky +2 -0
- data/spec/_cases_output/menu/menu_with_items.inky +5 -0
- data/spec/_cases_output/spacer/basic.inky +5 -0
- data/spec/_cases_output/spacer/with_attr.inky +6 -0
- data/spec/_cases_output/spacer/with_size.inky +5 -0
- data/spec/_cases_output/spacer/with_size_lg.inky +5 -0
- data/spec/_cases_output/spacer/with_size_sm.inky +5 -0
- data/spec/_cases_output/spacer/with_size_sm_and_lg.inky +5 -0
- data/spec/_cases_output/spacer/with_sizes_and_attr.inky +6 -0
- data/spec/_cases_output/wrapper/basic.inky +1 -0
- data/spec/_cases_output/wrapper/with_align.inky +1 -0
- data/spec/_cases_output/wrapper/with_attributes.inky +1 -0
- data/spec/cases/button/with_extra_attr.inky +3 -0
- data/spec/cases/button/with_link.inky +1 -1
- data/spec/cases/button/with_link_and_extra_attr.inky +3 -0
- data/spec/cases/h_line/basic.inky +1 -0
- data/spec/cases/h_line/multiple.inky +8 -0
- data/spec/cases/h_line/with_attr.inky +2 -0
- data/spec/cases/spacer/with_attr.inky +6 -0
- data/spec/cases/spacer/with_size.inky +1 -1
- data/spec/cases/spacer/with_size_lg.inky +1 -1
- data/spec/cases/spacer/with_size_sm.inky +1 -1
- data/spec/cases/spacer/with_size_sm_and_lg.inky +1 -1
- data/spec/cases/spacer/with_sizes_and_attr.inky +6 -0
- data/spec/components_spec.rb +48 -48
- data/spec/configuration_spec.rb +92 -22
- data/spec/grid_spec.rb +38 -38
- data/spec/spec_helper.rb +4 -1
- data/spec/test_app/log/test.log +5405 -0
- data/spec/test_app/spec/features/inky_spec.rb +3 -3
- metadata +165 -78
- data/Gemfile.lock +0 -188
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6292d929c4b925c5767a682f808c6f7f812925fe8769604e266459b19f0afb
|
4
|
+
data.tar.gz: 46349b5e9e7901e374e99d51f9bfbcaa1d083550336917629ea434c452ce4c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c9410bd6ff9a642ccd5c51d8435a077234334c6dcfe23054f72bd6dc330a2cd4d07cd02bd2084dc0f65bed18ba08d82b904d5b08ced59e23b0f553b3daf22e
|
7
|
+
data.tar.gz: 1479e4b652d006b7a37092a05ee72d1177e0ab97ea514f0eb646acc25900da9799f887176cee1bef2f9527ebd13936d208ed5818bad3a44fee0b88da1ebbfcf5
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -2,15 +2,17 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
4
|
- 2.0.0
|
5
|
-
- 2.
|
5
|
+
- 2.6.1
|
6
6
|
gemfile:
|
7
7
|
- gemfiles/rails_3.gemfile
|
8
8
|
- gemfiles/rails_4.gemfile
|
9
9
|
- gemfiles/rails_5.gemfile
|
10
|
+
- gemfiles/rails_6.gemfile
|
10
11
|
matrix:
|
11
12
|
exclude:
|
12
13
|
- rvm: 2.0.0
|
13
14
|
gemfile: gemfiles/rails_5.gemfile
|
15
|
+
- rvm: 2.0.0
|
16
|
+
gemfile: gemfiles/rails_6.gemfile
|
14
17
|
before_install:
|
15
|
-
- gem install bundler
|
16
18
|
- 'npm install -g inky-cli'
|
data/README.md
CHANGED
data/inky.gemspec
CHANGED
@@ -5,11 +5,11 @@ require 'inky/rails/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'inky-rb'
|
7
7
|
s.version = Inky::Rails::VERSION
|
8
|
-
s.summary = 'Inky is an HTML-based templating language that converts simple HTML into complex, responsive email-ready HTML. Designed for Foundation for Emails
|
9
|
-
s.description = 'Inky is an HTML-based templating language that converts simple HTML into complex, responsive email-ready HTML. Designed for Foundation for Emails
|
10
|
-
s.authors = ["
|
11
|
-
s.email = ['
|
12
|
-
s.homepage = 'https://github.com/
|
8
|
+
s.summary = 'Inky is an HTML-based templating language that converts simple HTML into complex, responsive email-ready HTML. Designed for Foundation for Emails'
|
9
|
+
s.description = 'Inky is an HTML-based templating language that converts simple HTML into complex, responsive email-ready HTML. Designed for Foundation for Emails'
|
10
|
+
s.authors = ["Foundation"]
|
11
|
+
s.email = ['contact@get.foundation']
|
12
|
+
s.homepage = 'https://github.com/foundation/inky-rb'
|
13
13
|
s.licenses = ['MIT']
|
14
14
|
|
15
15
|
s.files = `git ls-files -z`.split("\x0")
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency "foundation_emails", "~> 2"
|
20
20
|
s.add_dependency "nokogiri"
|
21
|
-
s.add_development_dependency "bundler"
|
21
|
+
s.add_development_dependency "bundler"
|
22
22
|
s.add_development_dependency "capybara"
|
23
23
|
s.add_development_dependency "rails"
|
24
24
|
s.add_development_dependency "rake"
|
@@ -12,6 +12,11 @@ module Inky
|
|
12
12
|
tags = tags.to_set if tags.respond_to? :to_set
|
13
13
|
IGNORED_ON_PASSTHROUGH = tags.freeze
|
14
14
|
|
15
|
+
# These constants are used to circumvent an issue with JRuby Nokogiri.
|
16
|
+
# For more details see https://github.com/zurb/inky-rb/pull/94
|
17
|
+
INTERIM_TH_TAG = 'inky-interim-th'.freeze
|
18
|
+
INTERIM_TH_TAG_REGEX = %r{(?<=\<|\<\/)#{Regexp.escape(INTERIM_TH_TAG)}}
|
19
|
+
|
15
20
|
def _pass_through_attributes(elem)
|
16
21
|
elem.attributes.reject { |e| IGNORED_ON_PASSTHROUGH.include?(e.downcase) }.map do |name, value|
|
17
22
|
%{#{name}="#{value}" }
|
@@ -40,27 +45,28 @@ module Inky
|
|
40
45
|
|
41
46
|
def _transform_button(component, inner)
|
42
47
|
expand = _has_class(component, 'expand')
|
48
|
+
attributes = _pass_through_attributes(component)
|
43
49
|
if component.attr('href')
|
44
50
|
target = _target_attribute(component)
|
45
51
|
extra = ' align="center" class="float-center"' if expand
|
46
|
-
inner = %{<a href="#{component.attr('href')}"#{target}#{extra}>#{inner}</a>}
|
52
|
+
inner = %{<a #{attributes}href="#{component.attr('href')}"#{target}#{extra}>#{inner}</a>}
|
47
53
|
end
|
48
54
|
inner = "<center>#{inner}</center>" if expand
|
49
55
|
|
50
56
|
classes = _combine_classes(component, 'button')
|
51
57
|
expander = '<td class="expander"></td>' if expand
|
52
|
-
%{<table class="#{classes}"><tr><td><table><tr><td>#{inner}</td></tr></table></td>#{expander}</tr></table>}
|
58
|
+
%{<table class="#{classes}"><tbody><tr><td><table><tbody><tr><td>#{inner}</td></tr></tbody></table></td>#{expander}</tr></tbody></table>}
|
53
59
|
end
|
54
60
|
|
55
61
|
def _transform_menu(component, inner)
|
56
62
|
attributes = _combine_attributes(component, 'menu')
|
57
|
-
%{<table #{attributes}><tr><td><table><tr>#{inner}</tr></table></td></tr></table>}
|
63
|
+
%{<table #{attributes}><tbody><tr><td><table><tbody><tr>#{inner}</tr></tbody></table></td></tr></tbody></table>}
|
58
64
|
end
|
59
65
|
|
60
66
|
def _transform_menu_item(component, inner)
|
61
67
|
target = _target_attribute(component)
|
62
68
|
attributes = _combine_attributes(component, 'menu-item')
|
63
|
-
%{
|
69
|
+
%{<#{INTERIM_TH_TAG} #{attributes}><a href="#{component.attr('href')}"#{target}>#{inner}</a></#{INTERIM_TH_TAG}>}
|
64
70
|
end
|
65
71
|
|
66
72
|
def _transform_container(component, inner)
|
@@ -91,12 +97,12 @@ module Inky
|
|
91
97
|
subrows = component.elements.css(".row").to_a.concat(component.elements.css("row").to_a)
|
92
98
|
expander = %{<th class="expander"></th>} if large_size.to_i == column_count && subrows.empty?
|
93
99
|
|
94
|
-
%{
|
100
|
+
%{<#{INTERIM_TH_TAG} class="#{classes}" #{_pass_through_attributes(component)}><table><tbody><tr><th>#{inner}</th>#{expander}</tr></tbody></table></#{INTERIM_TH_TAG}>}
|
95
101
|
end
|
96
102
|
|
97
103
|
def _transform_block_grid(component, inner)
|
98
104
|
classes = _combine_classes(component, "block-grid up-#{component.attr('up')}")
|
99
|
-
%{<table class="#{classes}"><tr>#{inner}</tr></table>}
|
105
|
+
%{<table class="#{classes}"><tbody><tr>#{inner}</tr></tbody></table>}
|
100
106
|
end
|
101
107
|
|
102
108
|
def _transform_center(component, _inner)
|
@@ -116,12 +122,12 @@ module Inky
|
|
116
122
|
def _transform_callout(component, inner)
|
117
123
|
classes = _combine_classes(component, 'callout-inner')
|
118
124
|
attributes = _pass_through_attributes(component)
|
119
|
-
%{<table #{attributes}class="callout"><tr><th class="#{classes}">#{inner}</th><th class="expander"></th></tr></table>}
|
125
|
+
%{<table #{attributes}class="callout"><tbody><tr><th class="#{classes}">#{inner}</th><th class="expander"></th></tr></tbody></table>}
|
120
126
|
end
|
121
127
|
|
122
128
|
def _transform_spacer(component, _inner)
|
123
129
|
classes = _combine_classes(component, 'spacer')
|
124
|
-
build_table = ->(size, extra) { %{<table class="#{classes} #{extra}"><tbody><tr><td height="#{size}
|
130
|
+
build_table = ->(size, extra) { %{<table class="#{classes} #{extra}"><tbody><tr><td height="#{size}" style="font-size:#{size}px;line-height:#{size}px;"> </td></tr></tbody></table>} }
|
125
131
|
size = component.attr('size')
|
126
132
|
size_sm = component.attr('size-sm')
|
127
133
|
size_lg = component.attr('size-lg')
|
@@ -135,9 +141,15 @@ module Inky
|
|
135
141
|
end
|
136
142
|
end
|
137
143
|
|
144
|
+
def _transform_h_line(component, _inner)
|
145
|
+
classes = _combine_classes(component, 'h-line')
|
146
|
+
attributes = _pass_through_attributes(component)
|
147
|
+
%{<table #{attributes}class="#{classes}"><tr><th> </th></tr></table>}
|
148
|
+
end
|
149
|
+
|
138
150
|
def _transform_wrapper(component, inner)
|
139
151
|
attributes = _combine_attributes(component, 'wrapper')
|
140
|
-
%{<table #{attributes} align="center"><tr><td class="wrapper-inner">#{inner}</td></tr></table>}
|
152
|
+
%{<table #{attributes} align="center"><tbody><tr><td class="wrapper-inner">#{inner}</td></tr></tbody></table>}
|
141
153
|
end
|
142
154
|
end
|
143
155
|
end
|
data/lib/inky/configuration.rb
CHANGED
@@ -7,6 +7,8 @@ module Inky
|
|
7
7
|
# Set Inky's configuration
|
8
8
|
# @param config [Inky::Configuration]
|
9
9
|
def self.configuration=(config)
|
10
|
+
raise TypeError, "Not an Inky::Configuration" unless config.is_a?(Configuration)
|
11
|
+
|
10
12
|
@configuration = config
|
11
13
|
end
|
12
14
|
|
@@ -23,11 +25,30 @@ module Inky
|
|
23
25
|
end
|
24
26
|
|
25
27
|
class Configuration
|
26
|
-
|
28
|
+
attr_reader :template_engine, :column_count, :components
|
27
29
|
|
28
30
|
def initialize
|
29
31
|
@template_engine = :erb
|
30
32
|
@column_count = 12
|
33
|
+
@components = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def template_engine=(value)
|
37
|
+
raise TypeError, "#{value.inspect} (#{value.class}) does not respond to 'to_sym'" unless value.respond_to?(:to_sym)
|
38
|
+
|
39
|
+
@template_engine = value.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
def components=(value)
|
43
|
+
raise TypeError, "#{value.inspect} (#{value.class}) does not respond to 'to_hash'" unless value.respond_to?(:to_hash)
|
44
|
+
|
45
|
+
@components = value.to_hash
|
46
|
+
end
|
47
|
+
|
48
|
+
def column_count=(value)
|
49
|
+
raise TypeError, "#{value.inspect} (#{value.class}) does not respond to 'to_int'" unless value.respond_to?(:to_int)
|
50
|
+
|
51
|
+
@column_count = value.to_int
|
31
52
|
end
|
32
53
|
end
|
33
54
|
end
|
@@ -13,9 +13,13 @@ module Inky
|
|
13
13
|
raise("No template handler found for #{type}")
|
14
14
|
end
|
15
15
|
|
16
|
-
def call(template)
|
17
|
-
compiled_source =
|
18
|
-
|
16
|
+
def call(template, source = nil)
|
17
|
+
compiled_source =
|
18
|
+
if source
|
19
|
+
engine_handler.call(template, source)
|
20
|
+
else
|
21
|
+
engine_handler.call(template)
|
22
|
+
end
|
19
23
|
"Inky::Core.new.release_the_kraken(begin; #{compiled_source};end)"
|
20
24
|
end
|
21
25
|
|
data/lib/inky/rails/version.rb
CHANGED
data/lib/inky.rb
CHANGED
@@ -20,8 +20,9 @@ module Inky
|
|
20
20
|
callout: 'callout',
|
21
21
|
spacer: 'spacer',
|
22
22
|
wrapper: 'wrapper',
|
23
|
-
menu_item: 'item'
|
24
|
-
|
23
|
+
menu_item: 'item',
|
24
|
+
h_line: 'h-line',
|
25
|
+
}.merge(::Inky.configuration.components).merge(options[:components] || {})
|
25
26
|
|
26
27
|
self.component_lookup = components.invert
|
27
28
|
|
@@ -40,6 +41,8 @@ module Inky
|
|
40
41
|
html = Nokogiri::HTML.public_send(parse_cmd, str)
|
41
42
|
transform_doc(html)
|
42
43
|
string = html.to_html
|
44
|
+
string.gsub!(INTERIM_TH_TAG_REGEX, 'th')
|
45
|
+
string.gsub!(' ', ' ') # Convert non-breaking spaces to explicit entity
|
43
46
|
Inky::Core.re_inject_raws(string, raws)
|
44
47
|
end
|
45
48
|
|
@@ -0,0 +1 @@
|
|
1
|
+
<table class="button"><tbody><tr><td><table><tbody><tr><td>I'm missing an href</td></tr></tbody></table></td></tr></tbody></table>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<table class="button noexpand"><tbody><tr><td><table><tbody><tr><td><a href="http://example.com">
|
2
|
+
A label
|
3
|
+
</a></td></tr></tbody></table></td></tr></tbody></table>
|
4
|
+
|
5
|
+
<table class="button expand-niet"><tbody><tr><td><table><tbody><tr><td><a href="http://example.com">
|
6
|
+
A label
|
7
|
+
</a></td></tr></tbody></table></td></tr></tbody></table>
|
8
|
+
|
9
|
+
<table class="button expand foo"><tbody><tr><td><table><tbody><tr><td><center><a href="http://example.com" align="center" class="float-center">
|
10
|
+
A label
|
11
|
+
</a></center></td></tr></tbody></table></td>
|
12
|
+
<td class="expander"></td></tr></tbody></table>
|
13
|
+
|
14
|
+
<table class="button foo expand"><tbody><tr><td><table><tbody><tr><td><center><a href="http://example.com" align="center" class="float-center">
|
15
|
+
A label
|
16
|
+
</a></center></td></tr></tbody></table></td>
|
17
|
+
<td class="expander"></td></tr></tbody></table>
|
18
|
+
|
19
|
+
<table class="button foo expand bar"><tbody><tr><td><table><tbody><tr><td><center><a href="http://example.com" align="center" class="float-center">
|
20
|
+
A label
|
21
|
+
</a></center></td></tr></tbody></table></td>
|
22
|
+
<td class="expander"></td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table class="callout"><tbody><tr><th class="callout-inner">Simple callout</th><th class="expander"></th></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
Very simple test...
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Text before
|
2
|
+
<table class="callout"><tbody><tr><th class="callout-inner">Ho</th><th class="expander"></th></tr></tbody></table>
|
3
|
+
Text after
|
4
|
+
<table class="callout"><tbody><tr><th class="callout-inner">Ho</th><th class="expander"></th></tr></tbody></table>
|
5
|
+
Text after
|
6
|
+
<table class="callout"><tbody><tr><th class="callout-inner">Ho</th><th class="expander"></th></tr></tbody></table>
|
7
|
+
Text after
|
@@ -0,0 +1 @@
|
|
1
|
+
<table foo="bar" align="center" class="container klass"><tbody><tr><td>some content</td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table align="left" class="container"><tbody><tr><td>some content</td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table foo="bar" class="row some klasses"><tbody><tr>columns here</tr></tbody></table>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<table class="row collapse"><tbody><tr>
|
2
|
+
<th class="small-12 large-4 columns first"><table><tbody><tr><th>First column</th></tr></tbody></table></th>
|
3
|
+
<th class="small-12 large-4 columns"><table><tbody><tr><th>Second column</th></tr></tbody></table></th>
|
4
|
+
<th class="small-12 large-4 columns last"><table><tbody><tr><th>Last column</th></tr></tbody></table></th>
|
5
|
+
</tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table class="h-line"><tr><th> </th></tr></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table class="h-line"><tr><th> </th></tr></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<th foo="bar" class="menu-item some classes"><a href="http://example.com">An item</a></th>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<table class="menu small-vertical"><tbody><tr><td><table><tbody><tr>
|
2
|
+
<th class="menu-item"><a href="http://example.com/1">An item</a></th>
|
3
|
+
<th class="menu-item"><a href="http://example.com/2">Another Item</a></th>
|
4
|
+
<th class="menu-item"><a href="http://example.com/3">Last Item</a></th>
|
5
|
+
</tr></tbody></table></td></tr></tbody></table>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<div>
|
2
|
+
Stuff on top
|
3
|
+
<table class="spacer some classes hide-for-large"><tbody><tr><td height="42" style="font-size:42px;line-height:42px;"> </td></tr></tbody></table><table class="spacer some classes show-for-large"><tbody><tr><td height="666" style="font-size:666px;line-height:666px;"> </td></tr></tbody></table>
|
4
|
+
Stuff on bottom
|
5
|
+
</div>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<!-- pending https://github.com/foundation/inky/issues/135 --->
|
2
|
+
<div>
|
3
|
+
Stuff on top
|
4
|
+
<table foo="bar" class="spacer some classes hide-for-large"><tbody><tr><td height="42" style="font-size:42px;line-height:42px;"> </td></tr></tbody></table><table foo="bar" class="spacer some classes show-for-large"><tbody><tr><td height="666" style="font-size:666px;line-height:666px;"> </td></tr></tbody></table>
|
5
|
+
Stuff on bottom
|
6
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table class="wrapper" align="center"><tbody><tr><td class="wrapper-inner">In the wrap</td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table align="left" class="wrapper"><tbody><tr><td class="wrapper-inner">In the wrap</td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<table foo="bar" class="wrapper some classes" align="center"><tbody><tr><td class="wrapper-inner">In the wrap</td></tr></tbody></table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h-line/>
|