locomotivecms_mounter 1.2.7 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locomotive/mounter/fields.rb +1 -1
- data/lib/locomotive/mounter/models/content_entry.rb +4 -4
- data/lib/locomotive/mounter/models/content_field.rb +19 -0
- data/lib/locomotive/mounter/models/content_type.rb +16 -2
- data/lib/locomotive/mounter/models/page.rb +7 -9
- data/lib/locomotive/mounter/models/snippet.rb +4 -7
- data/lib/locomotive/mounter/reader/api/site_reader.rb +3 -0
- data/lib/locomotive/mounter/reader/file_system/content_assets_reader.rb +1 -1
- data/lib/locomotive/mounter/reader/file_system/pages_reader.rb +12 -25
- data/lib/locomotive/mounter/reader/file_system/site_reader.rb +4 -1
- data/lib/locomotive/mounter/reader/file_system/snippets_reader.rb +2 -6
- data/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb +4 -1
- data/lib/locomotive/mounter/utils/yaml_front_matters_template.rb +45 -0
- data/lib/locomotive/mounter/version.rb +1 -1
- data/lib/locomotive/mounter.rb +1 -3
- metadata +17 -5
- data/lib/locomotive/mounter/extensions/tilt/haml.rb +0 -37
- data/lib/locomotive/mounter/extensions/tilt/liquid.rb +0 -23
- data/lib/locomotive/mounter/extensions/tilt/template.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a544f668acb9f469e36dbbc2481f94ca5be4e6b2
|
4
|
+
data.tar.gz: 2435a7ca2b750f20afbcafe77b5238b31090dbcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e24cb2022d27e11b981eb7e3b7c2c62786f562fb16fe71a8a5707e4d51e22b02b5c821f048c899727ef91919d495035eea36b55c3ba08b924aa61ab89ca16d7
|
7
|
+
data.tar.gz: 0f86671a344ac51f294eae9db59a04fabe5a6d2a0947dde51cb20be3b602dfe1f76d0948ff95dfb5eb24e8faa2b89273ec518c849f68391e1a9cd27b83a8504a
|
@@ -334,16 +334,16 @@ module Locomotive
|
|
334
334
|
field = self.content_type.find_field(field)
|
335
335
|
end
|
336
336
|
|
337
|
+
return nil if field.nil?
|
338
|
+
|
337
339
|
value = (self.dynamic_attributes || {})[field.name.to_sym]
|
338
340
|
|
339
|
-
# puts "[#{field.name.inspect}] #{value.inspect} / #{field.localized.inspect} / #{value.is_a?(Hash).inspect}"
|
341
|
+
# DEBUG puts "[#{field.name.inspect}] #{value.inspect} / #{field.localized.inspect} / #{value.is_a?(Hash).inspect}"
|
340
342
|
|
341
343
|
if !field.is_relationship? && field.localized && value.is_a?(Hash)
|
342
344
|
# get the localized value for the current locale
|
343
345
|
_value = value[Locomotive::Mounter.locale]
|
344
346
|
|
345
|
-
# puts "[#{field.name}] _value = #{value.inspect} / current #{Locomotive::Mounter.locale.inspect} / main #{self.main_locale.inspect}"
|
346
|
-
|
347
347
|
# no value for the current locale, give a try to the main one
|
348
348
|
if _value.nil? && Locomotive::Mounter.locale != self.main_locale
|
349
349
|
_value = value[self.main_locale]
|
@@ -352,7 +352,7 @@ module Locomotive
|
|
352
352
|
value = _value
|
353
353
|
end
|
354
354
|
|
355
|
-
value
|
355
|
+
value # DEBUG .tap { |v| puts "[#{field.name}] returning #{v.inspect}" }
|
356
356
|
end
|
357
357
|
|
358
358
|
end
|
@@ -53,6 +53,25 @@ module Locomotive
|
|
53
53
|
%w(belongs_to has_many many_to_many).include?(self.type.to_s)
|
54
54
|
end
|
55
55
|
|
56
|
+
# Tell if the id, the name of the field or other property based on
|
57
|
+
# its name (like formatted_<date field>) matches the parameter.
|
58
|
+
#
|
59
|
+
# @param [ String / Symbol] name_or_id Name or Id of the field
|
60
|
+
#
|
61
|
+
# @return [ Boolean ] True if the current field matches the parameter
|
62
|
+
#
|
63
|
+
def matches?(id_or_name)
|
64
|
+
default = [self._id, self.name]
|
65
|
+
|
66
|
+
list = default + (case self.type.to_sym
|
67
|
+
when :date, :date_time then ["formatted_#{self.name}"]
|
68
|
+
else
|
69
|
+
[]
|
70
|
+
end)
|
71
|
+
|
72
|
+
list.include?(id_or_name.to_s)
|
73
|
+
end
|
74
|
+
|
56
75
|
# Return the content type matching the class_name / target attribute
|
57
76
|
#
|
58
77
|
# @return [ Object ] The matching Content Type
|
@@ -49,6 +49,14 @@ module Locomotive
|
|
49
49
|
self.find_field(self.group_by_field_name)
|
50
50
|
end
|
51
51
|
|
52
|
+
# Return the order_by field
|
53
|
+
#
|
54
|
+
# @return [ Object ] The order_by field
|
55
|
+
#
|
56
|
+
def order_by_field
|
57
|
+
self.find_field(self.order_by)
|
58
|
+
end
|
59
|
+
|
52
60
|
# Build a content entry and add it to the list of entries of the content type.
|
53
61
|
# The content type will be referenced into the newly built entry .
|
54
62
|
#
|
@@ -68,8 +76,10 @@ module Locomotive
|
|
68
76
|
|
69
77
|
if field.nil? && v.is_a?(Hash) # not a dynamic field but localized (permalink ?)
|
70
78
|
entry.send(:"#{k}_translations=", v)
|
71
|
-
|
79
|
+
elsif field.nil?
|
72
80
|
entry.send(:"#{k}=", v)
|
81
|
+
else
|
82
|
+
entry.send(:"#{field.name}=", v)
|
73
83
|
end
|
74
84
|
rescue NoMethodError => e
|
75
85
|
Mounter.logger.error e.backtrace
|
@@ -117,7 +127,7 @@ module Locomotive
|
|
117
127
|
# @return [ Object ] The field if it exists or nil
|
118
128
|
#
|
119
129
|
def find_field(name_or_id)
|
120
|
-
self.fields.detect { |field| field.
|
130
|
+
self.fields.detect { |field| field.matches?(name_or_id) }
|
121
131
|
end
|
122
132
|
|
123
133
|
# Find a content entry by its ids (ie: _permalink or _label)
|
@@ -192,6 +202,10 @@ module Locomotive
|
|
192
202
|
# group by
|
193
203
|
_attributes['group_by'] = self.group_by_field.name if self.group_by_field
|
194
204
|
|
205
|
+
# order by
|
206
|
+
_attributes['order_by'] = self.order_by_field.name if self.order_by_field
|
207
|
+
_attributes['order_by'] = 'manually' if self.order_by == '_position'
|
208
|
+
|
195
209
|
# custom fields
|
196
210
|
_attributes['fields'] = self.fields
|
197
211
|
|
@@ -31,6 +31,9 @@ module Locomotive
|
|
31
31
|
## other accessors ##
|
32
32
|
attr_accessor :content_type_id, :content_entry, :parent_id, :children, :templatized_from_parent
|
33
33
|
|
34
|
+
## path to the file of the template (if mounted from a FS) ##
|
35
|
+
attr_accessor :filepath
|
36
|
+
|
34
37
|
## aliases ##
|
35
38
|
alias :listed? :listed
|
36
39
|
alias :published? :published
|
@@ -150,7 +153,7 @@ module Locomotive
|
|
150
153
|
self.depth * 100 + (self.position || 100)
|
151
154
|
end
|
152
155
|
|
153
|
-
# A layout is a page
|
156
|
+
# A layout is a page whose the template does
|
154
157
|
# not include the extend keyword.
|
155
158
|
# If the template is blank then, it is not considered as a layout
|
156
159
|
#
|
@@ -317,12 +320,7 @@ module Locomotive
|
|
317
320
|
if @source[Locomotive::Mounter.locale]
|
318
321
|
@source[Locomotive::Mounter.locale] # memoization
|
319
322
|
elsif self.template
|
320
|
-
|
321
|
-
# we do not know how to render the page so rethrow the exception
|
322
|
-
raise self.template
|
323
|
-
end
|
324
|
-
source = self.template.need_for_prerendering? ? self.template.render : self.template.data
|
325
|
-
@source[Locomotive::Mounter.locale] = source
|
323
|
+
@source[Locomotive::Mounter.locale] = self.template.source
|
326
324
|
else
|
327
325
|
nil
|
328
326
|
end
|
@@ -421,12 +419,12 @@ module Locomotive
|
|
421
419
|
# If a template is invalid, it is not considered as a
|
422
420
|
# blank one.
|
423
421
|
#
|
424
|
-
# @param [
|
422
|
+
# @param [ PageTemplate ] template The template to test
|
425
423
|
#
|
426
424
|
# @return [ Boolean ] True if the template is strictly blank
|
427
425
|
#
|
428
426
|
def template_blank?(template)
|
429
|
-
template.nil? ||
|
427
|
+
template.nil? || template.raw_source.strip.blank?
|
430
428
|
end
|
431
429
|
|
432
430
|
end
|
@@ -13,19 +13,16 @@ module Locomotive
|
|
13
13
|
## methods ##
|
14
14
|
|
15
15
|
# Return the Liquid template based on the template_filepath property
|
16
|
-
# of the snippet. If the template is HAML
|
16
|
+
# of the snippet. If the template is HAML, then a pre-rendering to Liquid is done.
|
17
17
|
#
|
18
18
|
# @return [ String ] The liquid template
|
19
19
|
#
|
20
20
|
def source
|
21
21
|
@source ||= {}
|
22
22
|
|
23
|
-
source = if self.template.respond_to?(:
|
24
|
-
#
|
25
|
-
self.template.
|
26
|
-
elsif self.template.is_a?(Exception) # comes from the parsing
|
27
|
-
# we do not know how to render the page so rethrow the exception
|
28
|
-
raise self.template
|
23
|
+
source = if self.template.respond_to?(:source)
|
24
|
+
# liquid or haml file
|
25
|
+
self.template.source
|
29
26
|
else
|
30
27
|
# simple string
|
31
28
|
self.template
|
@@ -69,16 +69,12 @@ module Locomotive
|
|
69
69
|
|
70
70
|
# Record pages found in file system
|
71
71
|
def fetch
|
72
|
-
folders = []
|
73
|
-
|
74
72
|
Dir.glob(File.join(self.root_dir, '**/*')).each do |filepath|
|
75
|
-
|
76
|
-
|
77
|
-
folders.push(fullpath) && next if File.directory?(filepath)
|
73
|
+
next unless File.directory?(filepath) || filepath =~ /\.(#{Locomotive::Mounter::TEMPLATE_EXTENSIONS.join('|')})$/
|
78
74
|
|
79
|
-
|
75
|
+
page = self.add(filepath)
|
80
76
|
|
81
|
-
|
77
|
+
next if File.directory?(filepath) || page.nil?
|
82
78
|
|
83
79
|
if locale = self.filepath_locale(filepath)
|
84
80
|
Locomotive::Mounter.with_locale(locale) do
|
@@ -88,28 +84,26 @@ module Locomotive
|
|
88
84
|
Locomotive::Mounter.logger.warn "Unknown locale in the '#{File.basename(filepath)}' file."
|
89
85
|
end
|
90
86
|
end
|
91
|
-
|
92
|
-
folders.each do |fullpath|
|
93
|
-
next if self.pages.key?(fullpath)
|
94
|
-
self.add(fullpath)
|
95
|
-
end
|
96
87
|
end
|
97
88
|
|
98
89
|
# Add a new page in the global hash of pages.
|
99
|
-
# If the page exists,
|
90
|
+
# If the page exists, override it.
|
100
91
|
#
|
101
|
-
# @param [ String ]
|
92
|
+
# @param [ String ] filepath The path of the template
|
102
93
|
# @param [ Hash ] attributes The attributes of the new page
|
103
94
|
#
|
104
95
|
# @return [ Object ] A newly created page or the existing one
|
105
96
|
#
|
106
|
-
def add(
|
97
|
+
def add(filepath, attributes = {})
|
98
|
+
fullpath = self.filepath_to_fullpath(filepath)
|
99
|
+
|
107
100
|
unless self.pages.key?(fullpath)
|
108
101
|
attributes[:title] = File.basename(fullpath).humanize
|
109
102
|
attributes[:fullpath] = fullpath
|
110
103
|
|
111
104
|
page = Locomotive::Mounter::Models::Page.new(attributes)
|
112
105
|
page.mounting_point = self.mounting_point
|
106
|
+
page.filepath = File.expand_path(filepath)
|
113
107
|
|
114
108
|
self.pages[fullpath] = page
|
115
109
|
end
|
@@ -125,16 +119,9 @@ module Locomotive
|
|
125
119
|
# @param [ String ] filepath The path of the template
|
126
120
|
#
|
127
121
|
def set_attributes_from_header(page, filepath)
|
128
|
-
|
129
|
-
template = Tilt.new(filepath)
|
130
|
-
rescue Haml::SyntaxError => e
|
131
|
-
Locomotive::Mounter.logger.warn "Invalid page template (#{filepath}): #{e.message}"
|
132
|
-
template = e
|
133
|
-
end
|
134
|
-
|
135
|
-
if template.respond_to?(:attributes)
|
136
|
-
return if template.attributes.blank?
|
122
|
+
template = Locomotive::Mounter::Utils::YAMLFrontMattersTemplate.new(filepath)
|
137
123
|
|
124
|
+
if template.attributes
|
138
125
|
attributes = template.attributes.clone
|
139
126
|
|
140
127
|
# set the editable elements
|
@@ -201,7 +188,7 @@ module Locomotive
|
|
201
188
|
def to_s(page = nil)
|
202
189
|
page ||= self.pages['index']
|
203
190
|
|
204
|
-
puts "#{" " * (page.try(:depth) + 1)} #{page.fullpath.inspect} (#{page.title}, position=#{page.position})"
|
191
|
+
puts "#{" " * (page.try(:depth) + 1)} #{page.fullpath.inspect} (#{page.title}, position=#{page.position}, template=#{page.template_translations.keys.inspect})"
|
205
192
|
|
206
193
|
(page.children || []).each { |child| self.to_s(child) }
|
207
194
|
end
|
@@ -13,7 +13,10 @@ module Locomotive
|
|
13
13
|
# set the default locale first
|
14
14
|
Locomotive::Mounter.locale = site['locales'].first.to_sym rescue Locomotive::Mounter.locale
|
15
15
|
|
16
|
-
Locomotive::Mounter::Models::Site.new(site)
|
16
|
+
Locomotive::Mounter::Models::Site.new(site).tap do |_site|
|
17
|
+
# set the time zone for the next Time operations (UTC by default)
|
18
|
+
Time.zone = ActiveSupport::TimeZone.new(_site.timezone || 'UTC')
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
end
|
@@ -40,7 +40,7 @@ module Locomotive
|
|
40
40
|
self.items.values.each do |snippet|
|
41
41
|
default_template = snippet.template
|
42
42
|
|
43
|
-
next if
|
43
|
+
next if default_template.blank?
|
44
44
|
|
45
45
|
self.locales.map(&:to_sym).each do |locale|
|
46
46
|
next if locale == self.default_locale
|
@@ -104,11 +104,7 @@ module Locomotive
|
|
104
104
|
# @return [ Object ] The Tilt template or the exception itself if the template is invalid
|
105
105
|
#
|
106
106
|
def fetch_template(filepath)
|
107
|
-
|
108
|
-
Tilt.new(filepath)
|
109
|
-
rescue Haml::SyntaxError => e
|
110
|
-
e
|
111
|
-
end
|
107
|
+
Locomotive::Mounter::Utils::YAMLFrontMattersTemplate.new(filepath)
|
112
108
|
end
|
113
109
|
|
114
110
|
end
|
@@ -39,8 +39,11 @@ module Locomotive
|
|
39
39
|
def list
|
40
40
|
return @list unless @list.nil?
|
41
41
|
|
42
|
+
# Follows symlinks and makes sure subdirectories are handled
|
43
|
+
glob_pattern = '**/*/**/*'
|
44
|
+
|
42
45
|
@list = [].tap do |list|
|
43
|
-
Dir.glob(File.join(self.root_dir,
|
46
|
+
Dir.glob(File.join(self.root_dir, glob_pattern)).each do |file|
|
44
47
|
next if self.exclude?(file)
|
45
48
|
|
46
49
|
folder = File.dirname(file.gsub("#{self.root_dir}/", ''))
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Mounter
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
# YAML Front-matters for HAML/Liquid templates
|
6
|
+
class YAMLFrontMattersTemplate
|
7
|
+
|
8
|
+
attr_accessor :filepath, :attributes, :raw_source, :line_offset
|
9
|
+
|
10
|
+
def initialize(filepath)
|
11
|
+
self.filepath = filepath
|
12
|
+
self.line_offset = 0
|
13
|
+
|
14
|
+
self.fetch_attributes_and_raw_source(File.read(self.filepath))
|
15
|
+
end
|
16
|
+
|
17
|
+
def source
|
18
|
+
return @source if @source
|
19
|
+
|
20
|
+
@source = if self.filepath.ends_with?('.haml')
|
21
|
+
Haml::Engine.new(self.raw_source).render
|
22
|
+
else
|
23
|
+
self.raw_source
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def fetch_attributes_and_raw_source(data)
|
30
|
+
if data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)(.*)/m
|
31
|
+
self.line_offset = $1.count("\n") + 1
|
32
|
+
self.attributes = YAML.load($1)
|
33
|
+
self.raw_source = $3
|
34
|
+
else
|
35
|
+
self.attributes = nil
|
36
|
+
self.raw_source = data
|
37
|
+
end
|
38
|
+
|
39
|
+
self.raw_source = self.raw_source.force_encoding('utf-8')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/locomotive/mounter.rb
CHANGED
@@ -27,6 +27,7 @@ require 'locomotive/mounter/utils/hash'
|
|
27
27
|
require 'locomotive/mounter/utils/yaml'
|
28
28
|
require 'locomotive/mounter/utils/string'
|
29
29
|
require 'locomotive/mounter/utils/output'
|
30
|
+
require 'locomotive/mounter/utils/yaml_front_matters_template'
|
30
31
|
|
31
32
|
# Main
|
32
33
|
require 'locomotive/mounter/version'
|
@@ -40,10 +41,7 @@ require 'locomotive/mounter/engine_api'
|
|
40
41
|
require 'locomotive/mounter/extensions/httmultiparty'
|
41
42
|
require 'locomotive/mounter/extensions/sprockets'
|
42
43
|
require 'locomotive/mounter/extensions/compass'
|
43
|
-
require 'locomotive/mounter/extensions/tilt/template'
|
44
44
|
require 'locomotive/mounter/extensions/tilt/css'
|
45
|
-
require 'locomotive/mounter/extensions/tilt/haml'
|
46
|
-
require 'locomotive/mounter/extensions/tilt/liquid'
|
47
45
|
|
48
46
|
# Models
|
49
47
|
require 'locomotive/mounter/models/base'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_mounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ~>
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 4.2.3
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: tzinfo
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.0.1
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.0.1
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: chronic
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -417,9 +431,6 @@ files:
|
|
417
431
|
- lib/locomotive/mounter/extensions/httmultiparty.rb
|
418
432
|
- lib/locomotive/mounter/extensions/sprockets.rb
|
419
433
|
- lib/locomotive/mounter/extensions/tilt/css.rb
|
420
|
-
- lib/locomotive/mounter/extensions/tilt/haml.rb
|
421
|
-
- lib/locomotive/mounter/extensions/tilt/liquid.rb
|
422
|
-
- lib/locomotive/mounter/extensions/tilt/template.rb
|
423
434
|
- lib/locomotive/mounter/fields.rb
|
424
435
|
- lib/locomotive/mounter/models/base.rb
|
425
436
|
- lib/locomotive/mounter/models/content_asset.rb
|
@@ -459,6 +470,7 @@ files:
|
|
459
470
|
- lib/locomotive/mounter/utils/output.rb
|
460
471
|
- lib/locomotive/mounter/utils/string.rb
|
461
472
|
- lib/locomotive/mounter/utils/yaml.rb
|
473
|
+
- lib/locomotive/mounter/utils/yaml_front_matters_template.rb
|
462
474
|
- lib/locomotive/mounter/version.rb
|
463
475
|
- lib/locomotive/mounter/writer/api/base.rb
|
464
476
|
- lib/locomotive/mounter/writer/api/content_assets_writer.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Tilt
|
2
|
-
|
3
|
-
# YAML Front-matters for HAML templates
|
4
|
-
class YamlFrontMattersHamlTemplate < HamlTemplate
|
5
|
-
|
6
|
-
# Attributes from YAML Front-matters header
|
7
|
-
attr_reader :attributes
|
8
|
-
|
9
|
-
def need_for_prerendering?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def prepare
|
14
|
-
if data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)(.*)/m
|
15
|
-
@attributes = YAML.load($1)
|
16
|
-
@data = $3
|
17
|
-
end
|
18
|
-
@data = @data.force_encoding('utf-8')
|
19
|
-
begin
|
20
|
-
super
|
21
|
-
rescue Haml::SyntaxError => e
|
22
|
-
# invalid haml so re-throw the exception but with keeping track of the attributes
|
23
|
-
e.attributes = @attributes
|
24
|
-
raise e
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
Tilt.register 'haml', YamlFrontMattersHamlTemplate
|
31
|
-
Tilt.prefer YamlFrontMattersHamlTemplate
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
class ::Haml::SyntaxError
|
36
|
-
attr_accessor :attributes
|
37
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Tilt
|
2
|
-
|
3
|
-
# YAML Front-matters for Liquid templates
|
4
|
-
class YamlFrontMattersLiquidTemplate < Template
|
5
|
-
|
6
|
-
# Attributes from YAML Front-matters header
|
7
|
-
attr_reader :attributes
|
8
|
-
|
9
|
-
def prepare
|
10
|
-
if data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)(.*)/m
|
11
|
-
@attributes = YAML.load($1)
|
12
|
-
@data = $3
|
13
|
-
end
|
14
|
-
@data = @data.force_encoding('utf-8')
|
15
|
-
# Note: do not call 'super' because we are going to use a different parse mechanism
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
Tilt.register 'liquid', YamlFrontMattersLiquidTemplate
|
21
|
-
Tilt.prefer YamlFrontMattersLiquidTemplate
|
22
|
-
|
23
|
-
end
|