glim-haml-converter 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/glim-haml-converter.rb +61 -4
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c20b0016ab07cdac94b5be9502a810050c88a644392e43299ffdd52d10eabfe
|
4
|
+
data.tar.gz: 220241d3175e1f6158e9a76bec0d4f5bd161215b5e926fbe44cce0e432f7ada5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3b75d2811278f9d7fc0b7683b8ea8402e3715a8758bdfe80e44f2ce63150ebfd7dec5c755533665453f1d69db38415969996c83e62319d68301caada7b627a
|
7
|
+
data.tar.gz: 3b233a3c4c0bf490d21b39cee14c27ae47699f81d9fcdb52a1a785f18d7ef8b1b52fca7172c57ac73aa5cdfa00808f008e1842ba69d8ea9da38e56f114c33675
|
data/glim-haml-converter.rb
CHANGED
@@ -1,12 +1,69 @@
|
|
1
1
|
require 'haml'
|
2
2
|
|
3
|
-
module
|
4
|
-
class
|
3
|
+
module GlimHAMLSupport
|
4
|
+
class ExposeLiquidFilters
|
5
|
+
def initialize(site, page)
|
6
|
+
@context = Liquid::Context.new({ 'site' => site, 'page' => page })
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(method, *args)
|
10
|
+
@context.strainer.invoke(method, *args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ExposeLiquidGetterAPI
|
15
|
+
def initialize(obj)
|
16
|
+
@obj = obj.to_liquid
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method, *args)
|
20
|
+
@obj.liquid_method_missing(method.to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class HAMLToHTML < Glim::Filter
|
5
25
|
transforms 'haml' => 'html'
|
6
26
|
|
27
|
+
def initialize(site)
|
28
|
+
@site = site
|
29
|
+
end
|
30
|
+
|
31
|
+
def transform(content, page, options)
|
32
|
+
engine = Haml::Engine.new(content, { :escape_attrs => :once })
|
33
|
+
content = engine.render(ExposeLiquidFilters.new(@site, page), :content => content, :page => ExposeLiquidGetterAPI.new(page), :site => ExposeLiquidGetterAPI.new(@site))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class HAMLLayout < Glim::Filter
|
38
|
+
transforms '*' => 'output'
|
39
|
+
|
40
|
+
def initialize(site)
|
41
|
+
@site = site
|
42
|
+
@cache = {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_layout(name)
|
46
|
+
unless name.nil? || @cache.has_key?(name)
|
47
|
+
path = File.join(@site.layouts_dir, name + '.haml')
|
48
|
+
@cache[name] = if File.exists?(path)
|
49
|
+
Glim::FileItem.new(@site, path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@cache[name]
|
53
|
+
end
|
54
|
+
|
7
55
|
def transform(content, page, options)
|
8
|
-
|
9
|
-
|
56
|
+
layout = page.data['layout']
|
57
|
+
if find_layout(layout)
|
58
|
+
while layout_file = find_layout(layout)
|
59
|
+
engine = Haml::Engine.new(layout_file.content('liquid'), { :escape_attrs => :once })
|
60
|
+
content = engine.render(ExposeLiquidFilters.new(@site, page), :content => content, :page => ExposeLiquidGetterAPI.new(page), :site => ExposeLiquidGetterAPI.new(@site))
|
61
|
+
layout = layout_file.data['layout']
|
62
|
+
end
|
63
|
+
content
|
64
|
+
else
|
65
|
+
super
|
66
|
+
end
|
10
67
|
end
|
11
68
|
end
|
12
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glim-haml-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allan Odgaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glim
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.5
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.5
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: haml
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|