inky-rb 1.3.7.0 → 1.3.7.1
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 +2 -0
- data/Gemfile.lock +119 -8
- data/README.md +27 -2
- data/inky.gemspec +6 -2
- data/lib/generators/inky/install_generator.rb +3 -2
- data/lib/generators/inky/templates/mailer_layout.html.erb +2 -2
- data/lib/generators/inky/templates/mailer_layout.html.haml +13 -0
- data/lib/generators/inky/templates/mailer_layout.html.slim +15 -0
- data/lib/inky.rb +9 -8
- data/lib/inky/component_factory.rb +139 -0
- data/lib/inky/configuration.rb +31 -0
- data/lib/inky/rails/engine.rb +1 -1
- data/lib/inky/rails/template_handler.rb +24 -8
- data/lib/inky/rails/version.rb +1 -1
- data/spec/configuration_spec.rb +38 -0
- data/spec/inky_spec.rb +19 -0
- data/spec/spec_helper.rb +5 -5
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/inky_controller.rb +9 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/mailers/application_mailer.rb +4 -0
- data/spec/test_app/app/views/inky/_inky_partial.html.inky +1 -0
- data/spec/test_app/app/views/inky/explicit_builder.html.inky-builder +1 -0
- data/spec/test_app/app/views/inky/explicit_slim.html.inky-slim +2 -0
- data/spec/test_app/app/views/inky/layout.html.erb +1 -0
- data/spec/test_app/app/views/inky/non_inky.html.erb +3 -0
- data/spec/test_app/app/views/inky/simple.html.inky +1 -0
- data/spec/test_app/app/views/inky/slim.html.inky +2 -0
- data/spec/test_app/app/views/layouts/application.html.erb +4 -0
- data/spec/test_app/app/views/layouts/inky_layout.html.inky +11 -0
- data/spec/test_app/config.ru +5 -0
- data/spec/test_app/config/application.rb +22 -0
- data/spec/test_app/config/boot.rb +5 -0
- data/spec/test_app/config/cable.yml +9 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +54 -0
- data/spec/test_app/config/environments/production.rb +86 -0
- data/spec/test_app/config/environments/test.rb +44 -0
- data/spec/test_app/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/test_app/config/initializers/assets.rb +11 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/test_app/config/initializers/secret_token.rb +1 -0
- data/spec/test_app/config/initializers/session_store.rb +3 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +23 -0
- data/spec/test_app/config/puma.rb +47 -0
- data/spec/test_app/config/routes.rb +3 -0
- data/spec/test_app/config/secrets.yml +22 -0
- data/spec/test_app/config/spring.rb +6 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/spec/features/inky_spec.rb +100 -0
- data/spec/test_app/spec/helper.rb +14 -0
- metadata +197 -5
- data/lib/component_factory.rb +0 -138
data/lib/component_factory.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
module ComponentFactory
|
2
|
-
def component_factory(elem)
|
3
|
-
inner = elem.children.map(&:to_s).join
|
4
|
-
# TODO: Handle changed names
|
5
|
-
transform_method = :"_transform_#{component_lookup[elem.name]}"
|
6
|
-
return unless respond_to?(transform_method)
|
7
|
-
send(transform_method, elem, inner)
|
8
|
-
end
|
9
|
-
|
10
|
-
tags = %w[class id href size large no-expander small target]
|
11
|
-
tags = tags.to_set if tags.respond_to? :to_set
|
12
|
-
IGNORED_ON_PASSTHROUGH = tags.freeze
|
13
|
-
|
14
|
-
def _pass_through_attributes(elem)
|
15
|
-
elem.attributes.reject { |e| IGNORED_ON_PASSTHROUGH.include?(e.downcase) }.map do |name, value|
|
16
|
-
%{#{name}="#{value}" }
|
17
|
-
end.join
|
18
|
-
end
|
19
|
-
|
20
|
-
def _has_class(elem, klass)
|
21
|
-
elem.attr('class') =~ /(^|\s)#{klass}($|\s)/
|
22
|
-
end
|
23
|
-
|
24
|
-
def _combine_classes(elem, extra_classes)
|
25
|
-
[elem['class'], extra_classes].join(' ')
|
26
|
-
end
|
27
|
-
|
28
|
-
def _combine_attributes(elem, extra_classes = nil)
|
29
|
-
classes = _combine_classes(elem, extra_classes)
|
30
|
-
[_pass_through_attributes(elem), classes && %{class="#{classes}"}].join
|
31
|
-
end
|
32
|
-
|
33
|
-
def _target_attribute(elem)
|
34
|
-
elem.attributes['target'] ? %{ target="#{elem.attributes['target']}"} : ''
|
35
|
-
end
|
36
|
-
|
37
|
-
def _transform_button(component, inner)
|
38
|
-
expand = _has_class(component, 'expand')
|
39
|
-
if component.attr('href')
|
40
|
-
target = _target_attribute(component)
|
41
|
-
extra = ' align="center" class="float-center"' if expand
|
42
|
-
inner = %{<a href="#{component.attr('href')}"#{target}#{extra}>#{inner}</a>}
|
43
|
-
end
|
44
|
-
inner = "<center>#{inner}</center>" if expand
|
45
|
-
|
46
|
-
classes = _combine_classes(component, 'button')
|
47
|
-
expander = '<td class="expander"></td>' if expand
|
48
|
-
%{<table class="#{classes}"><tr><td><table><tr><td>#{inner}</td></tr></table></td>#{expander}</tr></table>}
|
49
|
-
end
|
50
|
-
|
51
|
-
def _transform_menu(component, inner)
|
52
|
-
attributes = _combine_attributes(component, 'menu')
|
53
|
-
%{<table #{attributes}><tr><td><table><tr>#{inner}</tr></table></td></tr></table>}
|
54
|
-
end
|
55
|
-
|
56
|
-
def _transform_menu_item(component, inner)
|
57
|
-
target = _target_attribute(component)
|
58
|
-
attributes = _combine_attributes(component, 'menu-item')
|
59
|
-
%{<th #{attributes}><a href="#{component.attr('href')}"#{target}>#{inner}</a></th>}
|
60
|
-
end
|
61
|
-
|
62
|
-
def _transform_container(component, inner)
|
63
|
-
attributes = _combine_attributes(component, 'container')
|
64
|
-
%{<table #{attributes} align="center"><tbody><tr><td>#{inner}</td></tr></tbody></table>}
|
65
|
-
end
|
66
|
-
|
67
|
-
def _transform_row(component, inner)
|
68
|
-
attributes = _combine_attributes(component, 'row')
|
69
|
-
%{<table #{attributes}><tbody><tr>#{inner}</tr></tbody></table>}
|
70
|
-
end
|
71
|
-
|
72
|
-
# in inky.js this is factored out into makeClumn. TBD if we need that here.
|
73
|
-
def _transform_columns(component, inner)
|
74
|
-
col_count = component.parent.elements.size
|
75
|
-
|
76
|
-
small_val = component.attr('small')
|
77
|
-
large_val = component.attr('large')
|
78
|
-
|
79
|
-
small_size = small_val || column_count
|
80
|
-
large_size = large_val || small_val || (column_count / col_count).to_i
|
81
|
-
|
82
|
-
classes = _combine_classes(component, "small-#{small_size} large-#{large_size} columns")
|
83
|
-
|
84
|
-
classes << ' first' unless component.previous_element
|
85
|
-
classes << ' last' unless component.next_element
|
86
|
-
|
87
|
-
subrows = component.elements.css(".row").to_a.concat(component.elements.css("row").to_a)
|
88
|
-
expander = %{<th class="expander"></th>} if large_size.to_i == column_count && subrows.empty?
|
89
|
-
|
90
|
-
%{<th class="#{classes}" #{_pass_through_attributes(component)}><table><tr><th>#{inner}</th>#{expander}</tr></table></th>}
|
91
|
-
end
|
92
|
-
|
93
|
-
def _transform_block_grid(component, inner)
|
94
|
-
classes = _combine_classes(component, "block-grid up-#{component.attr('up')}")
|
95
|
-
%{<table class="#{classes}"><tr>#{inner}</tr></table>}
|
96
|
-
end
|
97
|
-
|
98
|
-
def _transform_center(component, _inner)
|
99
|
-
# NOTE: Using children instead of elements because elements.to_a
|
100
|
-
# sometimes appears to miss elements that show up in size
|
101
|
-
component.elements.each do |child|
|
102
|
-
child['align'] = 'center'
|
103
|
-
child['class'] = _combine_classes(child, 'float-center')
|
104
|
-
items = component.elements.css(".menu-item").to_a.concat(component.elements.css("item").to_a)
|
105
|
-
items.each do |item|
|
106
|
-
item['class'] = _combine_classes(item, 'float-center')
|
107
|
-
end
|
108
|
-
end
|
109
|
-
component.to_s
|
110
|
-
end
|
111
|
-
|
112
|
-
def _transform_callout(component, inner)
|
113
|
-
classes = _combine_classes(component, 'callout-inner')
|
114
|
-
attributes = _pass_through_attributes(component)
|
115
|
-
%{<table #{attributes}class="callout"><tr><th class="#{classes}">#{inner}</th><th class="expander"></th></tr></table>}
|
116
|
-
end
|
117
|
-
|
118
|
-
def _transform_spacer(component, _inner)
|
119
|
-
classes = _combine_classes(component, 'spacer')
|
120
|
-
build_table = ->(size, extra) { %{<table class="#{classes} #{extra}"><tbody><tr><td height="#{size}px" style="font-size:#{size}px;line-height:#{size}px;"> </td></tr></tbody></table>} }
|
121
|
-
size = component.attr('size')
|
122
|
-
size_sm = component.attr('size-sm')
|
123
|
-
size_lg = component.attr('size-lg')
|
124
|
-
if size_sm || size_lg
|
125
|
-
html = ''
|
126
|
-
html << build_table[size_sm, 'hide-for-large'] if size_sm
|
127
|
-
html << build_table[size_lg, 'show-for-large'] if size_lg
|
128
|
-
html
|
129
|
-
else
|
130
|
-
build_table[size || 16, nil]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def _transform_wrapper(component, inner)
|
135
|
-
attributes = _combine_attributes(component, 'wrapper')
|
136
|
-
%{<table #{attributes} align="center"><tr><td class="wrapper-inner">#{inner}</td></tr></table>}
|
137
|
-
end
|
138
|
-
end
|