hamloft 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +35 -34
- data/hamloft.gemspec +3 -3
- data/lib/hamloft/engine.rb +7 -11
- data/lib/hamloft/helpers.rb +26 -27
- data/lib/hamloft/style_builder.rb +26 -27
- data/lib/hamloft/template.rb +6 -7
- data/lib/hamloft/version.rb +1 -1
- data/lib/hamloft/widget.rb +3 -4
- data/lib/hamloft.rb +18 -18
- data/spec/fixtures/template/tumblr.rb +28 -30
- data/spec/fixtures/test.haml +4 -41
- data/spec/fixtures/widget/sample.rb +19 -0
- data/spec/hamloft_spec.rb +5 -11
- data/spec/spec_helper.rb +51 -53
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40807ee3a7e3517a4f34b52fda3c73a0a8dce5f2
|
4
|
+
data.tar.gz: 2e5eeb028f33fae5d926546ae6bb772f5c6336d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4060f0dba012feaecae55ac7539614f9eae4d6515827bd0171e67ae5ed95b3bd6d0e53b716dffa0f621c39ca08c779ecd36e23c801554490b7b42e600d3e7d54
|
7
|
+
data.tar.gz: 20e0feb0cc815a48b6c1a34c65495960e4e74737185b745170a442aaab658be8dc5485d51d72a1fbd77e99181d991112fa91cd16a5bc5b49d5da91c467e4220b
|
data/Gemfile.lock
CHANGED
@@ -1,56 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hamloft (0.2.
|
4
|
+
hamloft (0.2.5)
|
5
5
|
haml (~> 4.0)
|
6
|
-
nokogiri (~> 1.
|
6
|
+
nokogiri (~> 1.8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
ast (2.
|
12
|
-
astrolabe (1.3.1)
|
13
|
-
parser (~> 2.2)
|
11
|
+
ast (2.3.0)
|
14
12
|
coderay (1.1.0)
|
15
|
-
diff-lcs (1.
|
13
|
+
diff-lcs (1.3)
|
16
14
|
haml (4.0.7)
|
17
15
|
tilt
|
18
16
|
method_source (0.8.2)
|
19
|
-
mini_portile2 (2.
|
20
|
-
nokogiri (1.
|
21
|
-
mini_portile2 (~> 2.
|
22
|
-
|
23
|
-
parser (2.
|
24
|
-
ast (
|
25
|
-
pkg-config (1.1.7)
|
17
|
+
mini_portile2 (2.2.0)
|
18
|
+
nokogiri (1.8.0)
|
19
|
+
mini_portile2 (~> 2.2.0)
|
20
|
+
parallel (1.11.2)
|
21
|
+
parser (2.4.0.0)
|
22
|
+
ast (~> 2.2)
|
26
23
|
powerpack (0.1.1)
|
27
24
|
pry (0.10.3)
|
28
25
|
coderay (~> 1.1.0)
|
29
26
|
method_source (~> 0.8.1)
|
30
27
|
slop (~> 3.4)
|
31
|
-
rainbow (2.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
rspec-
|
36
|
-
|
37
|
-
rspec-
|
38
|
-
rspec-
|
28
|
+
rainbow (2.2.2)
|
29
|
+
rake
|
30
|
+
rake (12.0.0)
|
31
|
+
rspec (3.6.0)
|
32
|
+
rspec-core (~> 3.6.0)
|
33
|
+
rspec-expectations (~> 3.6.0)
|
34
|
+
rspec-mocks (~> 3.6.0)
|
35
|
+
rspec-core (3.6.0)
|
36
|
+
rspec-support (~> 3.6.0)
|
37
|
+
rspec-expectations (3.6.0)
|
39
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-mocks (3.
|
39
|
+
rspec-support (~> 3.6.0)
|
40
|
+
rspec-mocks (3.6.0)
|
42
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-support (3.
|
45
|
-
rubocop (0.
|
46
|
-
|
47
|
-
parser (>= 2.
|
42
|
+
rspec-support (~> 3.6.0)
|
43
|
+
rspec-support (3.6.0)
|
44
|
+
rubocop (0.49.1)
|
45
|
+
parallel (~> 1.10)
|
46
|
+
parser (>= 2.3.3.1, < 3.0)
|
48
47
|
powerpack (~> 0.1)
|
49
48
|
rainbow (>= 1.99.1, < 3.0)
|
50
|
-
ruby-progressbar (~> 1.
|
51
|
-
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
51
|
+
ruby-progressbar (1.8.1)
|
52
52
|
slop (3.6.0)
|
53
|
-
tilt (2.0.
|
53
|
+
tilt (2.0.7)
|
54
|
+
unicode-display_width (1.2.1)
|
54
55
|
|
55
56
|
PLATFORMS
|
56
57
|
ruby
|
@@ -58,8 +59,8 @@ PLATFORMS
|
|
58
59
|
DEPENDENCIES
|
59
60
|
hamloft!
|
60
61
|
pry (~> 0.10)
|
61
|
-
rspec (~> 3.
|
62
|
-
rubocop (~> 0.
|
62
|
+
rspec (~> 3.6)
|
63
|
+
rubocop (~> 0.49)
|
63
64
|
|
64
65
|
BUNDLED WITH
|
65
|
-
1.
|
66
|
+
1.14.6
|
data/hamloft.gemspec
CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = "Hamloft - MagLoft Widget Parser."
|
14
14
|
s.description = "This gem contains template built parser for creating MagLoft theme templates."
|
15
15
|
s.add_runtime_dependency 'haml', "~> 4.0"
|
16
|
-
s.add_runtime_dependency "nokogiri", "~> 1.
|
17
|
-
s.add_development_dependency "rspec", "~> 3.
|
16
|
+
s.add_runtime_dependency "nokogiri", "~> 1.8"
|
17
|
+
s.add_development_dependency "rspec", "~> 3.6"
|
18
18
|
s.add_development_dependency "pry", "~> 0.10"
|
19
|
-
s.add_development_dependency "rubocop", "~> 0.
|
19
|
+
s.add_development_dependency "rubocop", "~> 0.49"
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
22
22
|
s.require_path = 'lib'
|
data/lib/hamloft/engine.rb
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
module Hamloft
|
2
2
|
class Engine < Haml::Engine
|
3
|
-
|
4
3
|
def render(scope = Object.new, locals = {}, &block)
|
5
4
|
parent = scope.instance_variable_defined?('@haml_buffer') ? scope.instance_variable_get('@haml_buffer') : nil
|
6
5
|
buffer = Haml::Buffer.new(parent, @options.for_buffer)
|
7
6
|
|
8
7
|
if scope.is_a?(Binding) || scope.is_a?(Proc)
|
9
|
-
scope_object = eval(
|
10
|
-
scope = scope_object.instance_eval{binding} if block_given?
|
8
|
+
scope_object = eval('self', scope)
|
9
|
+
scope = scope_object.instance_eval { binding } if block_given?
|
11
10
|
else
|
12
11
|
scope_object = scope
|
13
|
-
scope = scope_object.instance_eval{binding}
|
12
|
+
scope = scope_object.instance_eval { binding }
|
14
13
|
end
|
15
14
|
|
16
|
-
set_locals(locals.merge(:
|
15
|
+
set_locals(locals.merge(_hamlout: buffer, _erbout: buffer.buffer), scope, scope_object)
|
17
16
|
|
18
17
|
scope_object.instance_eval do
|
19
18
|
extend Haml::Helpers
|
20
19
|
extend Hamloft::Helpers
|
21
|
-
|
20
|
+
|
22
21
|
# Inject widget helpers
|
23
22
|
Hamloft.widgets.each do |widget|
|
24
|
-
if defined?(widget::Helpers)
|
25
|
-
extend widget::Helpers
|
26
|
-
end
|
23
|
+
extend widget::Helpers if defined?(widget::Helpers)
|
27
24
|
end
|
28
|
-
|
25
|
+
|
29
26
|
@haml_buffer = buffer
|
30
27
|
end
|
31
28
|
begin
|
@@ -39,6 +36,5 @@ module Hamloft
|
|
39
36
|
@haml_buffer = buffer.upper if buffer
|
40
37
|
end
|
41
38
|
end
|
42
|
-
|
43
39
|
end
|
44
40
|
end
|
data/lib/hamloft/helpers.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Hamloft
|
2
2
|
module Helpers
|
3
|
-
|
4
3
|
def style_string(options, *args, &block)
|
5
4
|
Hamloft::StyleBuilder.new(options, args).process(block)
|
6
5
|
end
|
7
|
-
|
8
|
-
def block(identifier, variables={})
|
6
|
+
|
7
|
+
def block(identifier, variables = {})
|
9
8
|
haml_contents = Hamloft.block_resolver.resolve(identifier, @_haml_locals)
|
10
9
|
Hamloft.render(haml_contents, @_haml_locals.merge(variables))
|
11
10
|
end
|
@@ -14,25 +13,25 @@ module Hamloft
|
|
14
13
|
def asset(url)
|
15
14
|
"#{asset_uri}/themes/#{@_haml_locals[:theme]}/#{url}"
|
16
15
|
end
|
17
|
-
|
16
|
+
|
18
17
|
def root_asset(url)
|
19
18
|
"#{asset_uri}/#{url}"
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
def asset_uri
|
23
22
|
@_haml_locals[:asset_uri] || Hamloft.asset_uri
|
24
23
|
end
|
25
|
-
|
26
|
-
def var(key, default=nil)
|
24
|
+
|
25
|
+
def var(key, default = nil)
|
27
26
|
variable(:variables, {})[key.to_sym] || default
|
28
27
|
end
|
29
|
-
|
30
|
-
def variable(key, default=false)
|
28
|
+
|
29
|
+
def variable(key, default = false)
|
31
30
|
@_haml_locals[key.to_sym] || default
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
def parse_html(key, type)
|
35
|
-
if html = @_haml_locals[key.to_sym]
|
34
|
+
if (html = @_haml_locals[key.to_sym]) && !Hamloft.template(type).nil?
|
36
35
|
template = Hamloft.template(type).new(self, html)
|
37
36
|
template.container do
|
38
37
|
template.chunks.each do |chunk|
|
@@ -42,45 +41,45 @@ module Hamloft
|
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
def link(href, referrer=
|
46
|
-
if referrer
|
47
|
-
href = "#{href}#{href.include?(
|
44
|
+
def link(href, referrer = 'Baker', &block)
|
45
|
+
if referrer && !referrer.empty? && !href.include?('referrer=')
|
46
|
+
href = "#{href}#{href.include?('?') ? '&' : '?'}referrer=#{referrer}"
|
48
47
|
end
|
49
|
-
haml_tag :a, :
|
50
|
-
|
48
|
+
haml_tag :a, href: href do
|
49
|
+
yield if block
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
53
|
def font(font_face, &block)
|
55
|
-
haml_tag :font, :
|
56
|
-
|
54
|
+
haml_tag :font, face: font_face do
|
55
|
+
yield if block
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
59
|
def style(*args, &block)
|
61
60
|
style = nil
|
62
|
-
if args[-1].class.name ==
|
61
|
+
if args[-1].class.name == 'Hash'
|
63
62
|
style_options = args.pop
|
64
63
|
style = style_string(style_options, *style_options.keys)
|
65
64
|
end
|
66
|
-
|
67
|
-
classes = args.map{|a| "__#{a}"}
|
68
|
-
haml_tag :span, :
|
69
|
-
|
70
|
-
end
|
65
|
+
|
66
|
+
classes = args.map { |a| "__#{a}" }
|
67
|
+
haml_tag :span, class: classes.join(' '), style: style do
|
68
|
+
yield if block
|
69
|
+
end
|
71
70
|
end
|
72
71
|
|
73
72
|
# drop container
|
74
73
|
|
75
74
|
def drop_container
|
76
|
-
haml_tag :div, :
|
75
|
+
haml_tag :div, class: '_typeloft_widget_drop_container'
|
77
76
|
end
|
78
|
-
|
77
|
+
|
79
78
|
# widgets
|
80
79
|
|
81
80
|
def widget_block(widget, &block)
|
82
81
|
haml_tag :div, widget.typeloft_widget_options do
|
83
|
-
|
82
|
+
yield(widget) if block
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
@@ -3,64 +3,63 @@ module Hamloft
|
|
3
3
|
attr_accessor :options
|
4
4
|
attr_accessor :styles
|
5
5
|
|
6
|
-
def initialize(options, styles=[])
|
6
|
+
def initialize(options, styles = [])
|
7
7
|
@options = {}
|
8
8
|
@styles = {}
|
9
|
-
|
9
|
+
|
10
10
|
# expand margins
|
11
11
|
if styles.include?(:margin)
|
12
|
-
styles
|
13
|
-
styles.reject! {|
|
12
|
+
styles |= %i[margin_top margin_right margin_bottom margin_left]
|
13
|
+
styles.reject! { |_style| styles === :margin }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# expand paddings
|
17
17
|
if styles.include?(:padding)
|
18
|
-
styles
|
19
|
-
styles.reject! {|
|
18
|
+
styles |= %i[padding_top padding_right padding_bottom padding_left]
|
19
|
+
styles.reject! { |_style| styles === :padding }
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# build sanitized options
|
23
23
|
options.each do |k, v|
|
24
24
|
@options[sanitize_style(k)] = v
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# add initial styles
|
28
28
|
add_multi(styles)
|
29
29
|
end
|
30
|
-
|
31
|
-
def process(block=nil)
|
30
|
+
|
31
|
+
def process(block = nil)
|
32
32
|
block.call(self) if block
|
33
|
-
result = @styles.map{|k, v|"#{k}: #{v};"}.join(
|
33
|
+
result = @styles.map { |k, v| "#{k}: #{v};" }.join(' ')
|
34
34
|
result.empty? ? nil : result
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def add_multi(styles)
|
38
38
|
styles.each do |style|
|
39
39
|
add(style)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
def add(style, value=nil, template=nil)
|
42
|
+
|
43
|
+
def add(style, value = nil, template = nil)
|
44
44
|
style = sanitize_style(style)
|
45
|
-
|
45
|
+
|
46
46
|
# handle empty value field
|
47
|
-
if (
|
47
|
+
if (!value || value.empty?) && !(!(@options[style]) || @options[style].empty?)
|
48
48
|
value = @options[style]
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# apply template
|
52
|
-
if value
|
52
|
+
if value && !value.empty? && template && !template.empty?
|
53
53
|
value = ERB.new(template).result(binding)
|
54
54
|
end
|
55
|
-
|
56
|
-
@styles[style] = value if value
|
55
|
+
|
56
|
+
@styles[style] = value if value && !value.empty?
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def sanitize_style(value)
|
60
|
-
value.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2')
|
61
|
-
|
62
|
-
|
60
|
+
value.to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1-\2')
|
61
|
+
.gsub(/([a-z\d])([A-Z])/, '\1-\2')
|
62
|
+
.tr('_', '-').downcase
|
63
63
|
end
|
64
|
-
|
65
64
|
end
|
66
|
-
end
|
65
|
+
end
|
data/lib/hamloft/template.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module Hamloft
|
2
2
|
class Template
|
3
3
|
attr_accessor :haml, :html, :doc
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(haml, html)
|
6
6
|
self.haml = haml
|
7
7
|
self.html = html
|
8
|
-
|
8
|
+
self.doc = Nokogiri::HTML.fragment(self.html)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def chunks
|
12
12
|
[]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def container(&block)
|
16
16
|
yield(block)
|
17
17
|
end
|
18
|
-
|
19
|
-
def process_chunk(
|
18
|
+
|
19
|
+
def process_chunk(_chunk)
|
20
20
|
nil
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
end
|
data/lib/hamloft/version.rb
CHANGED
data/lib/hamloft/widget.rb
CHANGED
@@ -4,7 +4,7 @@ module Hamloft
|
|
4
4
|
attr_accessor :options
|
5
5
|
|
6
6
|
def identifier
|
7
|
-
|
7
|
+
'base'
|
8
8
|
end
|
9
9
|
|
10
10
|
def defaults
|
@@ -14,10 +14,10 @@ module Hamloft
|
|
14
14
|
def initialize(options)
|
15
15
|
@options = defaults.merge(options)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def typeloft_widget_options
|
19
19
|
attributes = {
|
20
|
-
:class =>
|
20
|
+
:class => '_typeloft_widget',
|
21
21
|
:"data-widget-identifier" => identifier
|
22
22
|
}
|
23
23
|
@options.each do |k, v|
|
@@ -25,6 +25,5 @@ module Hamloft
|
|
25
25
|
end
|
26
26
|
attributes
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
data/lib/hamloft.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
require 'haml'
|
2
|
+
require 'erb'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'hamloft/engine'
|
5
|
+
require 'hamloft/style_builder'
|
6
|
+
require 'hamloft/helpers'
|
7
|
+
require 'hamloft/template'
|
8
|
+
require 'hamloft/widget'
|
9
9
|
|
10
10
|
module Hamloft
|
11
11
|
@@_templates = {}
|
12
12
|
@@_widgets = []
|
13
13
|
@@_block_resolver = nil
|
14
14
|
@@_asset_uri = nil
|
15
|
-
|
15
|
+
|
16
16
|
def self.block_resolver=(resolver)
|
17
17
|
@@_block_resolver = resolver
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def self.block_resolver
|
21
21
|
@@_block_resolver
|
22
22
|
end
|
@@ -24,27 +24,27 @@ module Hamloft
|
|
24
24
|
def self.asset_uri=(asset_uri)
|
25
25
|
@@_asset_uri = asset_uri
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def self.asset_uri
|
29
|
-
@@_asset_uri ||
|
29
|
+
@@_asset_uri || '.'
|
30
30
|
end
|
31
|
-
|
32
|
-
def self.render(haml, variables={})
|
31
|
+
|
32
|
+
def self.render(haml, variables = {})
|
33
33
|
Hamloft::Engine.new(haml, remove_whitespace: true).render(Object.new, variables)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def self.register_template(key, template)
|
37
37
|
@@_templates[key] = template
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def self.register_widget(klass)
|
41
41
|
@@_widgets.push(klass)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def self.widgets
|
45
45
|
@@_widgets
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def self.template(key)
|
49
49
|
@@_templates[key]
|
50
50
|
end
|
@@ -1,52 +1,51 @@
|
|
1
1
|
class TumblrTemplate < Hamloft::Template
|
2
|
-
|
3
2
|
def chunks
|
4
|
-
|
3
|
+
doc.children
|
5
4
|
end
|
6
|
-
|
5
|
+
|
7
6
|
def container(&block)
|
8
|
-
haml.container_widget(padding_left:
|
7
|
+
haml.container_widget(padding_left: '0em', padding_right: '0em', &block)
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
def process_chunk(chunk)
|
12
11
|
case chunk.name
|
13
|
-
when
|
14
|
-
haml.paragraph_widget({margin_left:
|
15
|
-
when
|
16
|
-
haml.paragraph_widget({margin_left:
|
17
|
-
when
|
18
|
-
if chunk.css(
|
19
|
-
haml.image_widget_link(href: chunk.attribute(
|
12
|
+
when 'text'
|
13
|
+
haml.paragraph_widget({ margin_left: '2em', margin_right: '2em' }, chunk.text)
|
14
|
+
when 'p'
|
15
|
+
haml.paragraph_widget({ margin_left: '2em', margin_right: '2em' }, chunk.text)
|
16
|
+
when 'a'
|
17
|
+
if !chunk.css('img').empty?
|
18
|
+
haml.image_widget_link(href: chunk.attribute('href').to_s, source: chunk.css('img').first.attribute('src').to_s)
|
20
19
|
else
|
21
|
-
haml.paragraph_widget({margin_left:
|
22
|
-
haml.link(chunk.attribute(
|
20
|
+
haml.paragraph_widget({ margin_left: '2em', margin_right: '2em' }, chunk.text) do
|
21
|
+
haml.link(chunk.attribute('href').to_s)
|
23
22
|
end
|
24
23
|
end
|
25
|
-
when
|
24
|
+
when 'figure'
|
26
25
|
case chunk.children.first.name
|
27
|
-
when
|
28
|
-
haml.image_widget(source: chunk.children.first.attribute(
|
29
|
-
when
|
30
|
-
iframe_url = chunk.children.first.attribute(
|
31
|
-
if iframe_url.include?(
|
32
|
-
haml.yahoo_screen_widget(yahoo_screen_id: match[1], margin_bottom:
|
33
|
-
elsif iframe_url.include?(
|
34
|
-
haml.youtube_widget(youtube_id: match[1], margin_bottom:
|
26
|
+
when 'img'
|
27
|
+
haml.image_widget(source: chunk.children.first.attribute('src').to_s, margin_bottom: '1em')
|
28
|
+
when 'iframe'
|
29
|
+
iframe_url = chunk.children.first.attribute('src').value
|
30
|
+
if iframe_url.include?('screen.yahoo.com') && (match = iframe_url.match("screen\.yahoo\.com\/([a-z0-9\-]+)\.html"))
|
31
|
+
haml.yahoo_screen_widget(yahoo_screen_id: match[1], margin_bottom: '1em')
|
32
|
+
elsif iframe_url.include?('www.youtube.com') && (match = iframe_url.match("www\.youtube\.com\/.*\/([a-zA-Z0-9]+)"))
|
33
|
+
haml.youtube_widget(youtube_id: match[1], margin_bottom: '1em')
|
35
34
|
else
|
36
35
|
puts "-- unhandled iframe: #{iframe_url}"
|
37
36
|
end
|
38
37
|
else
|
39
38
|
puts "-- unhandled figure: #{chunk.children.first.name}"
|
40
39
|
end
|
41
|
-
when
|
42
|
-
if chunk.attribute(
|
43
|
-
haml.container_widget background_color:
|
44
|
-
haml.columns_widget columns:
|
40
|
+
when 'div'
|
41
|
+
if chunk.attribute('class').to_s == 'sponlogo'
|
42
|
+
haml.container_widget background_color: 'white', padding_left: '1em', padding_right: '1em', padding_bottom: '0.5em', padding_top: '1em' do
|
43
|
+
haml.columns_widget columns: '3x9' do |row|
|
45
44
|
haml.column row do
|
46
|
-
process_chunk(chunk.children
|
45
|
+
process_chunk(chunk.children[0])
|
47
46
|
end
|
48
47
|
haml.column row do
|
49
|
-
haml.paragraph_widget({align:
|
48
|
+
haml.paragraph_widget({ align: 'right' }, chunk.children[1].text)
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
@@ -61,5 +60,4 @@ class TumblrTemplate < Hamloft::Template
|
|
61
60
|
puts "-- unhandled chunk: #{chunk.name}"
|
62
61
|
end
|
63
62
|
end
|
64
|
-
|
65
63
|
end
|
data/spec/fixtures/test.haml
CHANGED
@@ -1,41 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
- container_widget min_height: "calc(100vh - 92px)", parallax_effect: "fixed", image_source: variable(:background_url, asset("images/bg/pastel-01.jpg")), image_size: "cover", background_color: "overlay", image_position: "top center" do
|
6
|
-
|
7
|
-
-# TOP PAGE CONTAINER
|
8
|
-
- container_widget min_height: "calc(100vh - 92px)" do
|
9
|
-
|
10
|
-
-# FIXED CONTAINER
|
11
|
-
- container_widget animate: "fade-in-down scroll-animate", style: "fixed", padding_top: "30vh", padding_left: "10vw", padding_right: "10vw" do
|
12
|
-
|
13
|
-
-# MAIN HEADING
|
14
|
-
- heading_widget align: "left", style: "feature" do
|
15
|
-
- style :bold, color: "#FFFFFF" do
|
16
|
-
= variable(:title, "WHY I DESIGN?")
|
17
|
-
|
18
|
-
- horizontal_rule_widget style: "flourish-01", color: "light"
|
19
|
-
|
20
|
-
-# CENTER CONTAINER
|
21
|
-
- container_widget style: "thin", background_color: "custom", bg_color: "rgba(255, 255, 255, 0.95)", padding_top: "1em", margin_bottom: "6em", animate: "fade-in-up" do
|
22
|
-
|
23
|
-
- container_widget padding_left: "1em", padding_right: "1em" do
|
24
|
-
|
25
|
-
- button_widget style: "success", href: "#scroll-next" do
|
26
|
-
- style :bold, color: "#FFFFFF" do
|
27
|
-
BEGIN
|
28
|
-
|
29
|
-
-# HEADER CONTAINER
|
30
|
-
- container_widget parallax_effect: "up", image_source: variable(:image_url, asset("images/base/bg/stripes.jpg")), margin_left: "1em", margin_right: "1em", margin_top: "1em", padding_top: "2em", padding_bottom: "2em", padding_left: "2em", padding_right: "2em" do
|
31
|
-
- heading_widget type: "h2", align: "center", style: "feature" do
|
32
|
-
- style :bold, color: "#FFFFFF" do
|
33
|
-
= variable(:title, "WHY I DESIGN?")
|
34
|
-
|
35
|
-
-# BODY CONTAINER
|
36
|
-
- container_widget padding_top: "2em", padding_left: "0em", padding_right: "0em" do
|
37
|
-
- parse_html(:html, :tumblr)
|
38
|
-
|
39
|
-
- button_widget style: "success", href: "#scroll-top" do
|
40
|
-
- style :bold, color: "#FFFFFF" do
|
41
|
-
BACK
|
1
|
+
- sample_widget do
|
2
|
+
SAMPLE
|
3
|
+
- sample_widget do
|
4
|
+
= variable(:title)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class SampleWidget < Hamloft::Widget
|
2
|
+
include Hamloft::Helpers
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
def identifier
|
6
|
+
'sample'
|
7
|
+
end
|
8
|
+
|
9
|
+
module Helpers
|
10
|
+
def sample_widget(options = {}, contents = nil, &block)
|
11
|
+
widget_block(SampleWidget.new(options)) do |_widget|
|
12
|
+
haml_tag :div, class: 'sample' do
|
13
|
+
haml_concat(contents) if contents
|
14
|
+
yield if block
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/hamloft_spec.rb
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
require 'hamloft'
|
2
2
|
RSpec.describe Hamloft do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Hamloft.
|
8
|
-
|
9
|
-
haml = File.read("spec/fixtures/test.haml")
|
10
|
-
results = Hamloft.render(haml, {
|
11
|
-
html: "<p>foo</p><p>bar</p>"
|
12
|
-
})
|
3
|
+
it 'renders a custom hamloft widget' do
|
4
|
+
require_relative 'fixtures/widget/sample.rb'
|
5
|
+
Hamloft.register_widget(SampleWidget)
|
6
|
+
haml = File.read('spec/fixtures/test.haml')
|
7
|
+
results = Hamloft.render(haml, title: 'TEST TITLE')
|
13
8
|
expect(results).to be_kind_of String
|
14
9
|
end
|
15
|
-
|
16
10
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,57 +41,55 @@ RSpec.configure do |config|
|
|
41
41
|
mocks.verify_partial_doubles = true
|
42
42
|
end
|
43
43
|
|
44
|
-
# The settings below are suggested to provide a good initial experience
|
45
|
-
# with RSpec, but feel free to customize to your heart's content.
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
config.
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# - http://
|
62
|
-
# - http://
|
63
|
-
#
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
Kernel.srand config.seed
|
96
|
-
=end
|
44
|
+
# The settings below are suggested to provide a good initial experience
|
45
|
+
# with RSpec, but feel free to customize to your heart's content.
|
46
|
+
# # These two settings work together to allow you to limit a spec run
|
47
|
+
# # to individual examples or groups you care about by tagging them with
|
48
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# # get run.
|
50
|
+
# config.filter_run :focus
|
51
|
+
# config.run_all_when_everything_filtered = true
|
52
|
+
#
|
53
|
+
# # Allows RSpec to persist some state between runs in order to support
|
54
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# # you configure your source control system to ignore this file.
|
56
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
#
|
58
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# # recommended. For more details, see:
|
60
|
+
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
61
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
63
|
+
# config.disable_monkey_patching!
|
64
|
+
#
|
65
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# # be too noisy due to issues in dependencies.
|
67
|
+
# config.warnings = true
|
68
|
+
#
|
69
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# # file, and it's useful to allow more verbose output when running an
|
71
|
+
# # individual spec file.
|
72
|
+
# if config.files_to_run.one?
|
73
|
+
# # Use the documentation formatter for detailed output,
|
74
|
+
# # unless a formatter has already been configured
|
75
|
+
# # (e.g. via a command-line flag).
|
76
|
+
# config.default_formatter = 'doc'
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# # Print the 10 slowest examples and example groups at the
|
80
|
+
# # end of the spec run, to help surface which specs are running
|
81
|
+
# # particularly slow.
|
82
|
+
# config.profile_examples = 10
|
83
|
+
#
|
84
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# # the seed, which is printed after each run.
|
87
|
+
# # --seed 1234
|
88
|
+
# config.order = :random
|
89
|
+
#
|
90
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# # test failures related to randomization by passing the same `--seed` value
|
93
|
+
# # as the one that triggered the failure.
|
94
|
+
# Kernel.srand config.seed
|
97
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamloft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Strebitzer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.49'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.49'
|
83
83
|
description: This gem contains template built parser for creating MagLoft theme templates.
|
84
84
|
email:
|
85
85
|
- tobias.strebitzer@magloft.com
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/hamloft/widget.rb
|
103
103
|
- spec/fixtures/template/tumblr.rb
|
104
104
|
- spec/fixtures/test.haml
|
105
|
+
- spec/fixtures/widget/sample.rb
|
105
106
|
- spec/hamloft_spec.rb
|
106
107
|
- spec/spec_helper.rb
|
107
108
|
homepage: http://www.magloft.com
|
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
127
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.6.
|
128
|
+
rubygems_version: 2.6.10
|
128
129
|
signing_key:
|
129
130
|
specification_version: 4
|
130
131
|
summary: Hamloft - MagLoft Widget Parser.
|