jekyll-template 0.15.0 → 0.16.0

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: 49d51afe697b5d9ee694a65e4bd7c2e2984a90e6
4
- data.tar.gz: 51e6027143c6fb8d1ccca573cf371be640ee2217
3
+ metadata.gz: c096e5fc9774d05776a63f7edcbe6b1dbd6befb8
4
+ data.tar.gz: 537f48aa6647e7094cde578fe87ae9382ae35565
5
5
  SHA512:
6
- metadata.gz: af69ac4cec5a3ffb31ecfb5cd94328dc80868bdce60be562576ad5390a658039da2f0d828b763dd2cd9b8ea112518a083b8dda1377a3b3201def3bcd680f0617
7
- data.tar.gz: 750e144ba45c4ed90ad641228734db84af2a9ea037d2b0df7aca9585f3387993b8d3b6d25aa691740a6167c777a01e5c36d259d18071fd056e7383a109a09037
6
+ metadata.gz: cc13346f93678b97352ce2b0ed1569da576faeef3e991762f616a7a144685312b02c6fc5248f9a5aa6e07ff22b0853f2eae5f4cc497312a6a91277e0a7897860
7
+ data.tar.gz: 311648fa21b511ea2faf014479944f4a7262079fa0dcddd4d0f7b1f087748648d7f3cbef7c3c40707740f2100c8dea437d85a26ef79b669e4d1517fdf8bb7d01
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency("jekyll", ">= 3.1.2")
24
24
  spec.add_runtime_dependency("htmlcompressor", "~> 0.3.1")
25
- spec.add_runtime_dependency("unindent", "~> 1.0")
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.13"
28
27
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,7 +1,6 @@
1
1
  require "htmlcompressor"
2
2
  require "jekyll"
3
3
  require "jekyll/template/version"
4
- require "unindent"
5
4
 
6
5
  module Jekyll
7
6
  module Tags
@@ -17,12 +16,12 @@ module Jekyll
17
16
  # Description: Extends Liquid's default initialize method.
18
17
  def initialize(tag_name, markup, tokens)
19
18
  super
20
- @root_path = false
19
+ @site = false
21
20
 
22
21
  # @template_name = markup
23
22
  if markup =~ Syntax
24
23
 
25
- @template_name = $1
24
+ @template_name = $1.freeze
26
25
  @attributes = {}
27
26
  @sanitize = false
28
27
 
@@ -36,12 +35,6 @@ module Jekyll
36
35
  end
37
36
  end
38
37
 
39
- # parse_content
40
- # Description: Extends Liquid's default parse_content method.
41
- def parse_content(context, content)
42
- content
43
- end
44
-
45
38
  # render
46
39
  # Description: Extends Liquid's default render method. This method also
47
40
  # adds additional features:
@@ -51,53 +44,39 @@ module Jekyll
51
44
  # - supports custom attributes to be used in template
52
45
  def render(context)
53
46
  content = super
54
- # Set the root_path
55
- @root_path = context.registers[:site].source
47
+ @site = context.registers[:site]
56
48
  # Remove leading whitespace
57
49
  # content = content.lstrip
58
50
  compressor = HtmlCompressor::Compressor.new({
59
51
  :remove_comments => true
60
52
  })
61
- site = context.registers[:site]
62
53
 
63
- add_template_to_dependency(site, @template_name, context)
54
+ add_template_to_dependency(@template_name, context)
55
+
64
56
  template_obj = load_cached_template(@template_name, context)
65
- template_data = template_obj["data"]
66
- update_attributes(template_data)
57
+ update_attributes(template_obj["data"])
67
58
 
68
59
  template = template_obj["template"]
69
60
 
70
61
  # Define the default template attributes
71
62
  # Source:
72
63
  # https://github.com/Shopify/liquid/blob/9a7778e52c37965f7b47673da09cfb82856a6791/lib/liquid/tags/include.rb
73
- context["template_name"] = context.evaluate(@template_name)
64
+ context["template_name"] = @template_name
74
65
  context["partial"] = true
75
66
  context["template"] = Hash.new
76
67
 
77
68
  # Parse and extend template's front-matter with content front-matter
78
- content_data = get_front_matter(content)
79
- update_attributes(content_data)
69
+ update_attributes(get_front_matter(content))
80
70
 
81
- # Remove front matter
82
- content = strip_front_matter(content)
83
-
84
71
  # Setting template attributes from @attributes
85
72
  # This allows for @attributes to be used within the template as
86
73
  # {{ template.atttribute_name }}
87
74
  if @attributes
88
- @attributes.each do |key, value|
89
- val = context.evaluate(value)
90
- context["template"][key] = val
91
-
92
- # Adjust sanitize if parse: html
93
- if (key == "parse") && (val == "html")
94
- @sanitize = true
95
- end
96
- end
75
+ @sanitize = @attributes["parse"] && @attributes["parse"] == "html"
76
+ context["template"].merge!(@attributes)
97
77
  end
98
78
 
99
- content = sanitize(site, parse_content(context, content))
100
- context["template"]["content"] = content
79
+ context["template"]["content"] = sanitize(strip_front_matter(content))
101
80
 
102
81
  compressor.compress(template.render(context))
103
82
  end
@@ -107,18 +86,17 @@ module Jekyll
107
86
  # @param data { hash }
108
87
  def update_attributes(data)
109
88
  if data
110
- @attributes = @attributes.merge(data)
89
+ @attributes.merge!(data)
111
90
  end
112
91
  end
113
92
 
114
- # add_template_to_dependency(site, path, context)
93
+ # add_template_to_dependency(path, context)
115
94
  # source: https://github.com/jekyll/jekyll/blob/e509cf2139d1a7ee11090b09721344608ecf48f6/lib/jekyll/tags/include.rb
116
- def add_template_to_dependency(site, path, context)
95
+ def add_template_to_dependency(path, context)
117
96
  if context.registers[:page] && context.registers[:page].key?("path")
118
- path = get_template_path(path)
119
- site.regenerator.add_dependency(
120
- site.in_source_dir(context.registers[:page]["path"]),
121
- path
97
+ @site.regenerator.add_dependency(
98
+ @site.in_source_dir(context.registers[:page]["path"]),
99
+ get_template_path(path)
122
100
  )
123
101
  end
124
102
  end
@@ -132,10 +110,7 @@ module Jekyll
132
110
  if cached_templates.key?(path)
133
111
  cached_templates[path]
134
112
  else
135
- begin
136
- template = load_template(context)
137
- cached_templates[path] = template
138
- end
113
+ cached_templates[path] = load_template()
139
114
  end
140
115
  end
141
116
 
@@ -143,10 +118,7 @@ module Jekyll
143
118
  # Returns: A full file path of the template
144
119
  # @param path { string }
145
120
  def get_template_path(path)
146
- # default template path
147
- dir = @root_path.to_s
148
- view = "_templates/" + path.to_s
149
- File.join(dir, view).to_s
121
+ File.join(@site.source.to_s, "_templates", path.to_s)
150
122
  end
151
123
 
152
124
  # get_template_content(template)
@@ -154,22 +126,18 @@ module Jekyll
154
126
  # Returns: Template content
155
127
  # @param template { string }
156
128
  def get_template_content(template)
157
- file_path = get_template_path(template)
158
- path = File.read(file_path.strip)
129
+ path = File.read(get_template_path(template).strip)
159
130
  end
160
131
 
161
- # load_template(context)
132
+ # load_template()
162
133
  # Description: Extends Liquid's default load_template method. Also provides
163
134
  # extra enhancements:
164
135
  # - parses and sets template front-matter content
165
136
  # Returns: Template class
166
- def load_template(context)
167
- # Set the root_path
168
- @root_path = context.registers[:site].source
169
- file_path = get_template_path(@template_name)
170
- file = context.registers[:site]
137
+ def load_template()
138
+ file = @site
171
139
  .liquid_renderer
172
- .file(file_path)
140
+ .file(get_template_path(@template_name))
173
141
  # Set the template_content
174
142
  template_content = get_template_content(@template_name)
175
143
 
@@ -186,19 +154,17 @@ module Jekyll
186
154
  end
187
155
  end
188
156
 
189
- # sanitize(site, content)
157
+ # sanitize(content)
190
158
  # Description: Renders the content as markdown or HTML based on the
191
159
  # "parse" attribute.
192
160
  # Returns: Content (string).
193
- # @param site { Jekyll site instance }
194
161
  # @param content { string }
195
- def sanitize(site, content)
162
+ def sanitize(content)
196
163
  unless @sanitize
197
- converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
198
- content = content.to_s.unindent
199
- content = converter.convert(content)
164
+ converter = @site.find_converter_instance(::Jekyll::Converters::Markdown)
165
+ content = converter.convert(unindent(content))
200
166
  else
201
- content = content.to_s.unindent
167
+ content = unindent(content)
202
168
  end
203
169
  end
204
170
 
@@ -208,13 +174,13 @@ module Jekyll
208
174
  # @param content { string }
209
175
  def unindent(content)
210
176
  # Remove initial whitespace
211
- content = content.gsub(/\A^\s*\n/, "")
177
+ content.gsub!(/\A^\s*\n/, "")
212
178
 
213
179
  # Remove indentations
214
180
  whitespace_regex = %r!^\s*!m
215
181
  if content =~ whitespace_regex
216
182
  indentation = Regexp.last_match(0).length
217
- content = content.gsub(/^\ {#{indentation}}/, "")
183
+ content.gsub!(/^\ {#{indentation}}/, "")
218
184
  end
219
185
 
220
186
  content
@@ -232,9 +198,7 @@ module Jekyll
232
198
  # Push YAML data to the template's attributes
233
199
  values = SafeYAML.load(front_matter)
234
200
  # Set YAML data to @attributes
235
- values.each do |key, value|
236
- data[key] = value
237
- end
201
+ data.merge!(values)
238
202
  # Returns data
239
203
  data
240
204
  end
@@ -251,7 +215,7 @@ module Jekyll
251
215
  if content =~ YAML_FRONT_MATTER_REGEXP
252
216
  front_matter = Regexp.last_match(0)
253
217
  # Returns content with stripped front-matter
254
- content = content.gsub(front_matter, "")
218
+ content.gsub!(front_matter, "")
255
219
  end
256
220
 
257
221
  content
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Template
3
- VERSION = "0.15.0"
3
+ VERSION = "0.16.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ItsJonQ
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.1
41
- - !ruby/object:Gem::Dependency
42
- name: unindent
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement