inky-rb 1.3.6.1 → 1.3.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74de32d25371bce184fdc11c8bd97d240e91d6e8
4
- data.tar.gz: 35d2d7fb902610d3cbe0ff3c1a7e259b65811483
3
+ metadata.gz: a70d84a75f2e9381d149d54dfb5fe9e965ad0dcb
4
+ data.tar.gz: dfb5d7fa5a16a9a332f6f0dcd31652b445a7df69
5
5
  SHA512:
6
- metadata.gz: a32921470b7797e53caa988ccef060bd6e4970980484d91af51e62dc447235893ba78933167c8788413fe9aacb7cd155532093e58a82787da3fa4938b66e9be8
7
- data.tar.gz: 3e9f7ff46e9d6c722633a54e6f008eb6b4ad8ad58ba9c3be3aa96afdda52a4503caa9f604670fd6be53443e41c5a4d69fdec10a313202628d7ab4735f4dfafdc
6
+ metadata.gz: 53b0a6662556687a5d52d498fe47963cf7e2f53cbdc3d60e54f48a4dfbff95c55eb615401827f21f5cfd37d5f8c8cad3a710d45d218ba05eb012d56394e1d70a
7
+ data.tar.gz: c2729bf8cddad5ed77eda40b3fd9d866b6bce67e6ef4480b0b5ddf9955758ebb58a9eb451242e9f87091b67b74ad834f805aa6145e1a3c1e5a7e0d82daf61491
@@ -0,0 +1,150 @@
1
+ # Relaxed.Ruby.Style
2
+
3
+ Style/Alias:
4
+ Enabled: false
5
+ StyleGuide: http://relaxed.ruby.style/#stylealias
6
+
7
+ Style/BeginBlock:
8
+ Enabled: false
9
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
10
+
11
+ Style/BlockDelimiters:
12
+ Enabled: false
13
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
18
+
19
+ Style/DotPosition:
20
+ Enabled: false
21
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
22
+
23
+ Style/DoubleNegation:
24
+ Enabled: false
25
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
26
+
27
+ Style/EndBlock:
28
+ Enabled: false
29
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
30
+
31
+ Style/FormatString:
32
+ Enabled: false
33
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
34
+
35
+ Style/IfUnlessModifier:
36
+ Enabled: false
37
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
38
+
39
+ Style/Lambda:
40
+ Enabled: false
41
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
42
+
43
+ Style/ModuleFunction:
44
+ Enabled: false
45
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
46
+
47
+ Style/MultilineBlockChain:
48
+ Enabled: false
49
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
50
+
51
+ Style/NegatedIf:
52
+ Enabled: false
53
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
54
+
55
+ Style/NegatedWhile:
56
+ Enabled: false
57
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
58
+
59
+ Style/ParallelAssignment:
60
+ Enabled: false
61
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
62
+
63
+ Style/PercentLiteralDelimiters:
64
+ Enabled: false
65
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
66
+
67
+ Style/PerlBackrefs:
68
+ Enabled: false
69
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
70
+
71
+ Style/Semicolon:
72
+ Enabled: false
73
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
74
+
75
+ Style/SignalException:
76
+ Enabled: false
77
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
78
+
79
+ Style/SingleLineBlockParams:
80
+ Enabled: false
81
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
82
+
83
+ Style/SingleLineMethods:
84
+ Enabled: false
85
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
86
+
87
+ Style/SpaceBeforeBlockBraces:
88
+ Enabled: false
89
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
90
+
91
+ Style/SpaceInsideParens:
92
+ Enabled: false
93
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
94
+
95
+ Style/SpecialGlobalVars:
96
+ Enabled: false
97
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
98
+
99
+ Style/StringLiterals:
100
+ Enabled: false
101
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
102
+
103
+ Style/TrailingCommaInLiteral:
104
+ Enabled: false
105
+ StyleGuide: http://relaxed.ruby.style/#styletrailingcommainliteral
106
+
107
+ Style/WhileUntilModifier:
108
+ Enabled: false
109
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
110
+
111
+ Lint/AmbiguousRegexpLiteral:
112
+ Enabled: false
113
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
114
+
115
+ Lint/AssignmentInCondition:
116
+ Enabled: false
117
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
118
+
119
+ Metrics/AbcSize:
120
+ Enabled: false
121
+
122
+ Metrics/BlockNesting:
123
+ Enabled: false
124
+
125
+ Metrics/ClassLength:
126
+ Enabled: false
127
+
128
+ Metrics/ModuleLength:
129
+ Enabled: false
130
+
131
+ Metrics/CyclomaticComplexity:
132
+ Enabled: false
133
+
134
+ Metrics/LineLength:
135
+ Enabled: false
136
+
137
+ Metrics/MethodLength:
138
+ Enabled: false
139
+
140
+ Metrics/ParameterLists:
141
+ Enabled: false
142
+
143
+ Metrics/PerceivedComplexity:
144
+ Enabled: false
145
+
146
+ # inky-rb gem specifics
147
+ Lint/HandleExceptions:
148
+ Exclude:
149
+ - 'Rakefile'
150
+ - 'lib/inky.rb'
@@ -1,14 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- inky-rb (1.3.6.1)
4
+ inky-rb (1.3.6.2)
5
5
  foundation_emails (~> 2)
6
+ nokogiri
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  diff-lcs (1.2.5)
11
12
  foundation_emails (2.2.0.0)
13
+ mini_portile2 (2.1.0)
14
+ nokogiri (1.6.8)
15
+ mini_portile2 (~> 2.1.0)
16
+ pkg-config (~> 1.1.7)
17
+ pkg-config (1.1.7)
12
18
  rake (11.2.2)
13
19
  rspec-core (3.5.0)
14
20
  rspec-support (~> 3.5.0)
@@ -28,4 +34,4 @@ DEPENDENCIES
28
34
  rspec-expectations
29
35
 
30
36
  BUNDLED WITH
31
- 1.11.2
37
+ 1.12.5
@@ -5,7 +5,6 @@ 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.date = '2016-02-12'
9
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, a responsive email framework from ZURB. '
10
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, a responsive email framework from ZURB. '
11
10
  s.authors = ["ZURB"]
@@ -16,6 +15,7 @@ Gem::Specification.new do |s|
16
15
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
16
 
18
17
  s.add_dependency "foundation_emails", "~> 2"
18
+ s.add_dependency "nokogiri"
19
19
  s.add_development_dependency "bundler", "~> 1.6"
20
20
  s.add_development_dependency "rake"
21
21
  end
@@ -2,151 +2,136 @@ module ComponentFactory
2
2
  def component_factory(elem)
3
3
  inner = elem.children.map(&:to_s).join
4
4
  # TODO: Handle changed names
5
- transform_method = :"_transform_#{self.component_lookup[elem.name]}"
6
- if self.respond_to?(transform_method)
7
- REXML::Document.new(self.send(transform_method, elem, inner)).root
8
- else
9
- nil
10
- end
5
+ transform_method = :"_transform_#{component_lookup[elem.name]}"
6
+ return unless respond_to?(transform_method)
7
+ Nokogiri::XML(send(transform_method, elem, inner)).root
11
8
  end
12
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
+
13
14
  def _pass_through_attributes(elem)
14
- ignored = ['class', 'id', 'href', 'size', 'large', 'no-expander', 'small', 'target'];
15
- elem.attributes.map do |name, value|
16
- if ignored.include?(name.downcase)
17
- ''
18
- else
19
- "#{name}=\"#{value}\""
20
- end
21
- end.join(' ')
15
+ elem.attributes.reject { |e| IGNORED_ON_PASSTHROUGH.include?(e.downcase) }.map do |name, value|
16
+ %{#{name}="#{value}" }
17
+ end.join
22
18
  end
23
19
 
24
20
  def _has_class(elem, klass)
25
- !!elem.attributes['class'] && elem.attributes['class'].split(' ').include?(klass)
21
+ (elem.attr('class') || '').include?(klass)
26
22
  end
27
23
 
28
24
  def _class_array(elem, defaults = [])
29
- (elem.attributes['class'] ? (defaults.concat(elem.attributes['class'].split(' '))) : defaults).uniq
25
+ classes = elem['class']
26
+ defaults.concat(classes.split(' ')) if classes
27
+ defaults
30
28
  end
31
29
 
32
30
  def _target_attribute(elem)
33
- elem.attributes['target'] ? " target=\"#{elem.attributes['target']}\"" : ''
31
+ elem.attributes['target'] ? %{ target="#{elem.attributes['target']}"} : ''
34
32
  end
35
33
 
36
34
  def _transform_button(component, inner)
37
35
  expand = _has_class(component, 'expand')
38
- if component.attributes['href']
36
+ if component.attr('href')
39
37
  target = _target_attribute(component)
40
- if expand
41
- inner = "<a href=\"#{component.attributes['href']}\"#{target} align=\"center\" class=\"float-center\">#{inner}</a>"
42
- else
43
- inner = "<a href=\"#{component.attributes['href']}\"#{target}>#{inner}</a>"
44
- end
38
+ extra = ' align="center" class="float-center"' if expand
39
+ inner = %{<a href="#{component.attr('href')}"#{target}#{extra}>#{inner}</a>}
45
40
  end
46
41
  inner = "<center>#{inner}</center>" if expand
47
42
 
48
43
  classes = _class_array(component, ['button'])
49
- if expand
50
- return "<table class=\"#{classes.join(' ')}\"><tr><td><table><tr><td>#{inner}</td></tr></table></td><td class=\"expander\"></td></tr></table>"
51
- else
52
- return "<table class=\"#{classes.join(' ')}\"><tr><td><table><tr><td>#{inner}</td></tr></table></td></tr></table>"
53
- end
44
+ expander = '<td class="expander"></td>' if expand
45
+ %{<table class="#{classes.join(' ')}"><tr><td><table><tr><td>#{inner}</td></tr></table></td>#{expander}</tr></table>}
54
46
  end
55
47
 
56
48
  def _transform_menu(component, inner)
57
49
  classes = _class_array(component, ['menu'])
58
- "<table class=\"#{classes.join(' ')}\"><tr><td><table><tr>#{inner}</tr></table></td></tr></table>"
50
+ %{<table class="#{classes.join(' ')}"><tr><td><table><tr>#{inner}</tr></table></td></tr></table>}
59
51
  end
60
52
 
61
53
  def _transform_menu_item(component, inner)
62
54
  target = _target_attribute(component)
63
- "<th class=\"menu-item\"><a href=\"#{component.attributes['href']}\"#{target}>#{inner}</a></th>"
55
+ %{<th class="menu-item"><a href="#{component.attr('href')}"#{target}>#{inner}</a></th>}
64
56
  end
65
57
 
66
58
  def _transform_container(component, inner)
67
59
  classes = _class_array(component, ['container'])
68
- "<table class=\"#{classes.join(' ')}\"><tbody><tr><td>#{inner}</td></tr></tbody></table>"
60
+ %{<table class="#{classes.join(' ')}"><tbody><tr><td>#{inner}</td></tr></tbody></table>}
69
61
  end
70
62
 
71
63
  def _transform_row(component, inner)
72
64
  classes = _class_array(component, ['row'])
73
65
  attrs = _pass_through_attributes(component)
74
- "<table #{attrs} class=\"#{classes.join(' ')}\"><tbody><tr>#{inner}</tr></tbody></table>"
66
+ %{<table #{attrs}class="#{classes.join(' ')}"><tbody><tr>#{inner}</tr></tbody></table>}
75
67
  end
76
68
 
77
69
  # in inky.js this is factored out into makeClumn. TBD if we need that here.
78
70
  def _transform_columns(component, inner)
79
-
80
71
  col_count = component.parent.elements.size
81
- small_size = component.attributes['small'] || self.column_count
82
- large_size = component.attributes['large'] || component.attributes['small'] || (self.column_count / col_count).to_i
83
72
 
84
- classes = _class_array(component, ["small-#{small_size}", "large-#{large_size}", "columns"])
73
+ small_val = component.attr('small')
74
+ large_val = component.attr('large')
75
+
76
+ small_size = small_val || column_count
77
+ large_size = large_val || small_val || (column_count / col_count).to_i
85
78
 
79
+ classes = _class_array(component, ["small-#{small_size}", "large-#{large_size}", "columns"])
86
80
 
87
81
  classes.push('first') unless component.previous_element
88
82
  classes.push('last') unless component.next_element
89
83
 
90
- subrows = component.elements.to_a("//*[contains(@class,'row')]").concat(component.elements.to_a("//row"))
91
- expander = ''
92
- if large_size.to_i == self.column_count && subrows.size == 0
93
- expander = "<th class=\"expander\"></th>"
94
- end
95
- "<th class=\"#{classes.join(' ')}\"><table><tr><th>#{inner}</th>#{expander}</tr></table></th>"
84
+ subrows = component.elements.css(".row").to_a.concat(component.elements.css("row").to_a)
85
+ expander = %{<th class="expander"></th>} if large_size.to_i == column_count && subrows.empty?
86
+
87
+ %{<th class="#{classes.join(' ')}" #{_pass_through_attributes(component)}><table><tr><th>#{inner}</th>#{expander}</tr></table></th>}
96
88
  end
97
89
 
98
90
  def _transform_block_grid(component, inner)
99
- classes = _class_array(component, ['block-grid', "up-#{component.attributes['up']}"])
100
- "<table class=\"#{classes.join(' ')}\"><tr>#{inner}</tr></table>"
91
+ classes = _class_array(component, ['block-grid', "up-#{component.attr('up')}"])
92
+ %{<table class="#{classes.join(' ')}"><tr>#{inner}</tr></table>}
101
93
  end
102
94
 
103
- def _transform_center(component, inner)
95
+ def _transform_center(component, _inner)
104
96
  # NOTE: Using children instead of elements because elements.to_a
105
97
  # sometimes appears to miss elements that show up in size
106
- component.elements.to_a.each do |child|
107
- child.add_attribute('align', 'center')
98
+ component.elements.each do |child|
99
+ child['align'] = 'center'
108
100
  child_classes = _class_array(child, ['float-center'])
109
- child.add_attribute('class', child_classes.join(' '))
110
- items = component.elements.to_a("//*[contains(@class,'menu-item')]").concat(component.elements.to_a("//item"))
101
+ child['class'] = child_classes.join(' ')
102
+ items = component.elements.css(".menu-item").to_a.concat(component.elements.css("item").to_a)
111
103
  items.each do |item|
112
104
  item_classes = _class_array(item, ['float-center'])
113
- item.add_attribute('class', item_classes.join(' '))
105
+ item['class'] = item_classes.join(' ')
114
106
  end
115
107
  end
116
- return component.to_s
108
+ component.to_s
117
109
  end
118
110
 
119
111
  def _transform_callout(component, inner)
120
112
  classes = _class_array(component, ['callout-inner'])
121
- return "<table class=\"callout\"><tr><th class=\"#{classes.join(' ')}\">#{inner}</th><th class=\"expander\"></th></tr></table>"
113
+ %{<table class="callout"><tr><th class="#{classes.join(' ')}">#{inner}</th><th class="expander"></th></tr></table>}
122
114
  end
123
115
 
124
- def _transform_spacer(component, inner)
116
+ def _transform_spacer(component, _inner)
125
117
  classes = _class_array(component, ['spacer'])
126
- size = component.attributes['size']
127
- size_sm = component.attributes['size-sm']
128
- size_lg = component.attributes['size-lg']
118
+ build_table = ->(size, extra) { %{<table class="#{classes.join(' ')} #{extra}"><tbody><tr><td height="#{size}px" style="font-size:#{size}px;line-height:#{size}px;">&#xA0;</td></tr></tbody></table>} }
119
+ size = component.attr('size')
120
+ size_sm = component.attr('size-sm')
121
+ size_lg = component.attr('size-lg')
129
122
  if size_sm || size_lg
130
123
  html = ''
131
- if size_sm
132
- html += "<table class=\"#{classes.join(' ')} hide-for-large\"><tbody><tr><td height=\"#{size_sm}px\" style=\"font-size:#{size_sm}px;line-height:#{size_sm}px;\">&#xA0;</td></tr></tbody></table>"
133
- end
134
- if size_lg
135
- html += "<table class=\"#{classes.join(' ')} show-for-large\"><tbody><tr><td height=\"#{size_lg}px\" style=\"font-size:#{size_lg}px;line-height:#{size_lg}px;\">&#xA0;</td></tr></tbody></table>"
136
- end
137
- if size_sm && size_lg
138
- # REXML doesn't like replacing a single element with a double
139
- html = "<span>#{html}</span>"
140
- end
141
- return html
124
+ html << build_table[size_sm, 'hide-for-large'] if size_sm
125
+ html << build_table[size_lg, 'show-for-large'] if size_lg
126
+ html = "<span>#{html}</span>" if size_sm && size_lg
127
+ html
142
128
  else
143
- size ||= 16
144
- return "<table class=\"#{classes.join(' ')}\"><tbody><tr><td height=\"#{size}px\" style=\"font-size:#{size}px;line-height:#{size}px;\">&#xA0;</td></tr></tbody></table>"
129
+ build_table[size || 16, nil]
145
130
  end
146
131
  end
147
132
 
148
133
  def _transform_wrapper(component, inner)
149
134
  classes = _class_array(component, ['wrapper'])
150
- return "<table class=\"#{classes.join(' ')}\" align=\"center\"><tr><td class=\"wrapper-inner\">#{inner}</td></tr></table>"
135
+ %{<table class="#{classes.join(' ')}" align="center"><tr><td class="wrapper-inner">#{inner}</td></tr></table>}
151
136
  end
152
137
  end
@@ -5,14 +5,14 @@ module Inky
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  desc 'Install Foundation for Emails'
7
7
  source_root File.join(File.dirname(__FILE__), 'templates')
8
- argument :layout_name, :type => :string, :default => 'mailer', :banner => 'layout_name'
8
+ argument :layout_name, type: :string, default: 'mailer', banner: 'layout_name'
9
9
 
10
10
  def preserve_original_mailer_layout
11
- return nil unless layout_name == 'mailer'
11
+ return unless layout_name == 'mailer'
12
12
 
13
13
  original_mailer = File.join(layouts_base_dir, 'mailer.html.erb')
14
14
  rename_filename = File.join(layouts_base_dir, "old_mailer_#{Time.now.to_i}.html.erb")
15
- File.rename(original_mailer, rename_filename) if File.exists? original_mailer
15
+ File.rename(original_mailer, rename_filename) if File.exist? original_mailer
16
16
  end
17
17
 
18
18
  def create_mailer_stylesheet
@@ -1,6 +1,6 @@
1
1
  module Inky
2
2
  class Core
3
- require 'rexml/document'
3
+ require 'nokogiri'
4
4
  require 'component_factory'
5
5
  attr_accessor :components, :column_count, :component_lookup, :component_tags
6
6
 
@@ -21,27 +21,22 @@ module Inky
21
21
  menu_item: 'item'
22
22
  }.merge(options[:components] || {})
23
23
 
24
- self.component_lookup = self.components.invert
24
+ self.component_lookup = components.invert
25
25
 
26
26
  self.column_count = options[:column_count] || 12
27
27
 
28
- self.component_tags = self.components.values
28
+ self.component_tags = components.values
29
29
  end
30
30
 
31
-
32
31
  def release_the_kraken(xml_string)
33
32
  xml_string = xml_string.gsub(/doctype/i, 'DOCTYPE')
34
33
  raws, str = Inky::Core.extract_raws(xml_string)
35
- xml_doc = REXML::Document.new(str)
36
- if self.components_exist?(xml_doc)
37
- self.transform_doc(xml_doc.root)
38
- end
39
- str = xml_doc.to_s
40
- return Inky::Core.re_inject_raws(str, raws)
34
+ xml_doc = Nokogiri::XML(str)
35
+ transform_doc(xml_doc.root) if components_exist?(xml_doc)
36
+ Inky::Core.re_inject_raws(xml_doc.to_s, raws)
41
37
  end
42
38
 
43
-
44
- def components_exist?(xml_doc)
39
+ def components_exist?(_xml_doc)
45
40
  true
46
41
  end
47
42
 
@@ -50,8 +45,8 @@ module Inky
50
45
  elem.children.each do |child|
51
46
  transform_doc(child)
52
47
  end
53
- component = self.component_factory(elem)
54
- elem.replace_with(component) if component
48
+ component = component_factory(elem)
49
+ elem.replace(component) if component
55
50
  end
56
51
  elem
57
52
  end
@@ -59,22 +54,24 @@ module Inky
59
54
  def self.extract_raws(string)
60
55
  raws = []
61
56
  i = 0
62
- regex = /\< *raw *\>(.*?)\<\/ *raw *\>/i;
57
+ regex = %r(< *raw *>(.*?)</ *raw *>)
63
58
  str = string
64
59
  while raw = str.match(regex)
65
60
  raws[i] = raw[1]
66
61
  str = str.sub(regex, "###RAW#{i}###")
67
- i = i + 1
62
+ i += 1
68
63
  end
69
- return [raws, str]
70
- end
64
+ [raws, str]
65
+ end
71
66
 
72
67
  def self.re_inject_raws(string, raws)
73
68
  str = string
74
69
  raws.each_with_index do |val, i|
75
70
  str = str.sub("###RAW#{i}###", val)
76
71
  end
77
- return str
72
+ # If we're in rails, these should be considered safe strings
73
+ str = str.html_safe if str.respond_to?(:html_safe)
74
+ str
78
75
  end
79
76
  end
80
77
  end
@@ -4,7 +4,7 @@ module Inky
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
6
  if config.respond_to?(:annotations)
7
- config.annotations.register_extensions("inky") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
7
+ config.annotations.register_extensions("inky") { |annotation| %r(//\s*(#{annotation}):?\s*(.*)$) }
8
8
  end
9
9
  end
10
10
  end
@@ -1,13 +1,15 @@
1
1
  module Inky
2
2
  module Rails
3
3
  class TemplateHandler
4
- def self.erb_handler
5
- @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
6
- end
4
+ class << self
5
+ def erb_handler
6
+ @erb_handler ||= ActionView::Template.registered_template_handler(:erb)
7
+ end
7
8
 
8
- def self.call(template)
9
- compiled_source = erb_handler.call(template)
10
- "Inky::Core.new.release_the_kraken(begin; #{compiled_source};end)"
9
+ def call(template)
10
+ compiled_source = erb_handler.call(template)
11
+ "Inky::Core.new.release_the_kraken(begin; #{compiled_source};end)"
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -1,5 +1,5 @@
1
1
  module Inky
2
2
  module Rails
3
- VERSION = "1.3.6.1"
3
+ VERSION = "1.3.6.2".freeze
4
4
  end
5
5
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe "Center" do
4
4
  it "applies a text-center class and center alignment attribute to the first child" do
5
- input = '<center><div></div></center>';
5
+ input = '<center><div></div></center>'
6
6
  expected = <<-HTML
7
7
  <center>
8
8
  <div align="center" class="float-center"></div>
9
9
  </center>
10
10
  HTML
11
11
 
12
- compare(input, expected);
12
+ compare(input, expected)
13
13
  end
14
14
 
15
15
  it "doesn't choke if center tags are nested" do
@@ -23,7 +23,7 @@ RSpec.describe "Center" do
23
23
  </center>
24
24
  HTML
25
25
 
26
- compare(input, expected);
26
+ compare(input, expected)
27
27
  end
28
28
 
29
29
  it "applies the class float-center to <item> elements" do
@@ -47,13 +47,13 @@ RSpec.describe "Center" do
47
47
  </center>
48
48
  HTML
49
49
 
50
- compare(input, expected);
50
+ compare(input, expected)
51
51
  end
52
52
  end
53
53
 
54
54
  RSpec.describe "Button" do
55
55
  it "creates a simple button" do
56
- input = '<button href="http://zurb.com">Button</button>';
56
+ input = '<button href="http://zurb.com">Button</button>'
57
57
  expected = <<-HTML
58
58
  <table class="button">
59
59
  <tr>
@@ -67,7 +67,7 @@ RSpec.describe "Button" do
67
67
  </tr>
68
68
  </table>
69
69
  HTML
70
- compare(input, expected);
70
+ compare(input, expected)
71
71
  end
72
72
 
73
73
  it 'creates a button with target="_blank" attribute' do
@@ -224,7 +224,7 @@ end
224
224
 
225
225
  RSpec.describe "Callout" do
226
226
  it "creates a callout with correct syntax" do
227
- input = '<callout>Callout</callout>';
227
+ input = '<callout>Callout</callout>'
228
228
  expected = <<-HTML
229
229
  <table class="callout">
230
230
  <tr>
@@ -234,7 +234,7 @@ RSpec.describe "Callout" do
234
234
  </table>
235
235
  HTML
236
236
 
237
- compare(input, expected);
237
+ compare(input, expected)
238
238
  end
239
239
 
240
240
  it "copies classes to the final HTML" do
@@ -248,13 +248,13 @@ RSpec.describe "Callout" do
248
248
  </table>
249
249
  HTML
250
250
 
251
- compare(input, expected);
251
+ compare(input, expected)
252
252
  end
253
253
  end
254
-
254
+
255
255
  RSpec.describe "Spacer" do
256
256
  it 'creates a spacer element with correct size' do
257
- input = '<spacer size="10"></spacer>';
257
+ input = '<spacer size="10"></spacer>'
258
258
  expected = <<-HTML
259
259
  <table class="spacer">
260
260
  <tbody>
@@ -265,7 +265,7 @@ RSpec.describe "Spacer" do
265
265
  </table>
266
266
  HTML
267
267
 
268
- compare(input, expected);
268
+ compare(input, expected)
269
269
  end
270
270
 
271
271
  it 'creates a spacer element for small screens with correct size' do
@@ -334,7 +334,7 @@ RSpec.describe "Spacer" do
334
334
  </table>
335
335
  HTML
336
336
 
337
- compare(input, expected);
337
+ compare(input, expected)
338
338
  end
339
339
  end
340
340
 
@@ -349,14 +349,14 @@ RSpec.describe "Wrapper" do
349
349
  </table>
350
350
  HTML
351
351
 
352
- compare(input, expected);
352
+ compare(input, expected)
353
353
  end
354
354
  end
355
355
 
356
356
  RSpec.describe "raw" do
357
357
  it 'creates a wrapper that ignores anything inside' do
358
- input = "<raw><<LCG Program\TG LCG Coupon Code Default='246996'>></raw>"
359
- expected = "<<LCG Program\TG LCG Coupon Code Default='246996'>>"
358
+ input = "<body><raw><<LCG Program\TG LCG Coupon Code Default='246996'>></raw></body>"
359
+ expected = "<?xml version=\"1.0\"?>\n<body><<LCG ProgramTG LCG Coupon Code Default='246996'>></body>\n"
360
360
 
361
361
  # Can't do vanilla compare because the second will fail to parse
362
362
  inky = Inky::Core.new
@@ -46,7 +46,7 @@ end
46
46
  RSpec.describe 'Grid' do
47
47
  it 'creates a row' do
48
48
  input = '<row></row>'
49
- expected = <<-HTML
49
+ expected = <<-HTML
50
50
  <table class="row">
51
51
  <tbody>
52
52
  <tr></tr>
@@ -155,7 +155,7 @@ RSpec.describe 'Grid' do
155
155
  compare(input, expected)
156
156
  end
157
157
 
158
- #if it just has small, borrow from small for large
158
+ # if it just has small, borrow from small for large
159
159
  it 'automatically assigns large columns if no large attribute is assigned' do
160
160
  input = <<-HTML
161
161
  <body>
@@ -214,6 +214,35 @@ RSpec.describe 'Grid' do
214
214
  compare(input, expected)
215
215
  end
216
216
 
217
+ it 'assigns small as full width and large as half width if neither is defined and there are two columns' do
218
+ input = <<-INKY
219
+ <body>
220
+ <columns>One</columns>
221
+ <columns>Two</columns>
222
+ </body>
223
+ INKY
224
+ expected = <<-HTML
225
+ <body>
226
+ <th class="small-12 large-6 columns first">
227
+ <table>
228
+ <tr>
229
+ <th>One</th>
230
+ </tr>
231
+ </table>
232
+ </th>
233
+ <th class="small-12 large-6 columns last">
234
+ <table>
235
+ <tr>
236
+ <th>Two</th>
237
+ </tr>
238
+ </table>
239
+ </th>
240
+ </body>
241
+ HTML
242
+
243
+ compare(input, expected)
244
+ end
245
+
217
246
  it 'supports nested grids' do
218
247
  input = '<row><columns><row></row></columns></row>'
219
248
  expected = <<-HTML
@@ -240,6 +269,23 @@ RSpec.describe 'Grid' do
240
269
 
241
270
  compare(input, expected)
242
271
  end
272
+
273
+ it 'transfers attributes like valign' do
274
+ input = '<columns small="6" valign="middle" foo="bar">x</columns>'
275
+ expected = <<-HTML
276
+ <th class="small-6 large-6 columns first last" valign="middle" foo="bar">
277
+ <table>
278
+ <tr>
279
+ <th>
280
+ x
281
+ </th>
282
+ </tr>
283
+ </table>
284
+ </th>
285
+ HTML
286
+
287
+ compare(input, expected)
288
+ end
243
289
  end
244
290
 
245
291
  RSpec.describe 'Block Grid' do
@@ -264,5 +310,4 @@ RSpec.describe 'Block Grid' do
264
310
 
265
311
  compare(input, expected)
266
312
  end
267
-
268
313
  end
@@ -1,6 +1,5 @@
1
1
  require 'inky'
2
2
 
3
- require 'rexml/document'
4
3
  def compare(input, expected)
5
4
  inky = Inky::Core.new
6
5
  output = inky.release_the_kraken(input)
@@ -8,7 +7,7 @@ def compare(input, expected)
8
7
  # TODO: Figure out a better way to do html compare in ruby..
9
8
  # this is overly dependent on things like class ordering, making it
10
9
  # fragile
11
- output_str = REXML::Document.new(output).to_s.gsub(/\s/, '')
12
- expected_str = REXML::Document.new(expected).to_s.gsub(/\s/, '')
10
+ output_str = Nokogiri::XML(output).to_s.gsub(/\s/, '')
11
+ expected_str = Nokogiri::XML(expected).to_s.gsub(/\s/, '')
13
12
  expect(output_str).to eql(expected_str)
14
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inky-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6.1
4
+ version: 1.3.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZURB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foundation_emails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -62,6 +76,7 @@ extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
78
  - ".gitignore"
79
+ - ".rubocop.yml"
65
80
  - Gemfile
66
81
  - Gemfile.lock
67
82
  - README.md