locomotivecms_mounter 1.0.0.alpha3 → 1.0.0.alpha4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/locomotive/mounter/extensions/tilt/haml.rb +11 -1
- data/lib/locomotive/mounter/models/page.rb +20 -3
- data/lib/locomotive/mounter/models/snippet.rb +4 -1
- data/lib/locomotive/mounter/reader/file_system/pages_reader.rb +6 -1
- data/lib/locomotive/mounter/reader/file_system/snippets_reader.rb +43 -2
- data/lib/locomotive/mounter/version.rb +1 -1
- metadata +3 -3
@@ -16,7 +16,13 @@ module Tilt
|
|
16
16
|
@data = $3
|
17
17
|
end
|
18
18
|
@data = @data.force_encoding('utf-8')
|
19
|
-
|
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
|
20
26
|
end
|
21
27
|
|
22
28
|
end
|
@@ -24,4 +30,8 @@ module Tilt
|
|
24
30
|
Tilt.register 'haml', YamlFrontMattersHamlTemplate
|
25
31
|
Tilt.prefer YamlFrontMattersHamlTemplate
|
26
32
|
|
33
|
+
end
|
34
|
+
|
35
|
+
class ::Haml::SyntaxError
|
36
|
+
attr_accessor :attributes
|
27
37
|
end
|
@@ -249,7 +249,7 @@ module Locomotive
|
|
249
249
|
def set_default_template_for_each_locale(default_locale)
|
250
250
|
default_template = self.template_translations[default_locale.to_sym]
|
251
251
|
|
252
|
-
return if
|
252
|
+
return if self.template_blank?(default_template)
|
253
253
|
|
254
254
|
self.translated_in.each do |locale|
|
255
255
|
next if locale.to_s == default_locale.to_s
|
@@ -258,8 +258,7 @@ module Locomotive
|
|
258
258
|
_template = self.template_translations[locale]
|
259
259
|
|
260
260
|
# is it blank ?
|
261
|
-
if
|
262
|
-
# puts "YOUPI #{self.fullpath} / #{locale} / #{default_template.data}"
|
261
|
+
if self.template_blank?(_template)
|
263
262
|
self.template_translations[locale] = default_template
|
264
263
|
end
|
265
264
|
end
|
@@ -285,6 +284,10 @@ module Locomotive
|
|
285
284
|
if @source[Locomotive::Mounter.locale]
|
286
285
|
@source[Locomotive::Mounter.locale] # memoization
|
287
286
|
elsif self.template
|
287
|
+
if self.template.is_a?(Exception) # comes from the parsing
|
288
|
+
# we do not know how to render the page so rethrow the exception
|
289
|
+
raise self.template
|
290
|
+
end
|
288
291
|
source = self.template.need_for_prerendering? ? self.template.render : self.template.data
|
289
292
|
@source[Locomotive::Mounter.locale] = source
|
290
293
|
else
|
@@ -370,6 +373,20 @@ module Locomotive
|
|
370
373
|
self.fullpath_or_default
|
371
374
|
end
|
372
375
|
|
376
|
+
protected
|
377
|
+
|
378
|
+
# Tell if a template is strictly blank (nil or empty).
|
379
|
+
# If a template is invalid, it is not considered as a
|
380
|
+
# blank one.
|
381
|
+
#
|
382
|
+
# @param [ Object ] template The template to test (Tilt)
|
383
|
+
#
|
384
|
+
# @return [ Boolean ] True if the template is strictly blank
|
385
|
+
#
|
386
|
+
def template_blank?(template)
|
387
|
+
template.nil? || (!template.is_a?(Exception) && template.data.strip.blank?)
|
388
|
+
end
|
389
|
+
|
373
390
|
end
|
374
391
|
|
375
392
|
end
|
@@ -20,9 +20,12 @@ module Locomotive
|
|
20
20
|
def source
|
21
21
|
@source ||= {}
|
22
22
|
|
23
|
-
source = if template.respond_to?(:need_for_prerendering?)
|
23
|
+
source = if self.template.respond_to?(:need_for_prerendering?)
|
24
24
|
# must be a tilt template with or without prerendering
|
25
25
|
self.template.need_for_prerendering? ? self.template.render : self.template.data
|
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
|
26
29
|
else
|
27
30
|
# simple string
|
28
31
|
self.template
|
@@ -122,7 +122,12 @@ module Locomotive
|
|
122
122
|
# @param [ String ] filepath The path of the template
|
123
123
|
#
|
124
124
|
def set_attributes_from_header(page, filepath)
|
125
|
-
|
125
|
+
begin
|
126
|
+
template = Tilt.new(filepath)
|
127
|
+
rescue Haml::SyntaxError => e
|
128
|
+
Locomotive::Mounter.logger.warn "Invalid page template (#{filepath}): #{e.message}"
|
129
|
+
template = e
|
130
|
+
end
|
126
131
|
|
127
132
|
if template.respond_to?(:attributes)
|
128
133
|
return if template.attributes.blank?
|
@@ -12,6 +12,8 @@ module Locomotive
|
|
12
12
|
def read
|
13
13
|
self.fetch_from_filesystem
|
14
14
|
|
15
|
+
self.set_default_template_for_each_locale
|
16
|
+
|
15
17
|
self.items
|
16
18
|
end
|
17
19
|
|
@@ -25,7 +27,29 @@ module Locomotive
|
|
25
27
|
snippet = self.add(filepath)
|
26
28
|
|
27
29
|
Locomotive::Mounter.with_locale(self.filepath_locale(filepath)) do
|
28
|
-
snippet.template =
|
30
|
+
snippet.template = self.fetch_template(filepath)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set a default template (coming from the default locale)
|
36
|
+
# for each snippet which does not have a translated version
|
37
|
+
# of the template in each locale.
|
38
|
+
#
|
39
|
+
def set_default_template_for_each_locale
|
40
|
+
self.items.values.each do |snippet|
|
41
|
+
default_template = snippet.template
|
42
|
+
|
43
|
+
next if !default_template.is_a?(Exception) && default_template.blank?
|
44
|
+
|
45
|
+
self.locales.map(&:to_sym).each do |locale|
|
46
|
+
next if locale == self.default_locale
|
47
|
+
|
48
|
+
_template = snippet.template_translations[locale]
|
49
|
+
|
50
|
+
if !_template.is_a?(Exception) && _template.blank?
|
51
|
+
snippet.template_translations[locale] = default_template
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
31
55
|
end
|
@@ -53,7 +77,7 @@ module Locomotive
|
|
53
77
|
self.items[slug] = Locomotive::Mounter::Models::Snippet.new({
|
54
78
|
name: slug.humanize,
|
55
79
|
slug: slug,
|
56
|
-
template:
|
80
|
+
template: self.fetch_template(filepath)
|
57
81
|
})
|
58
82
|
end
|
59
83
|
|
@@ -70,6 +94,23 @@ module Locomotive
|
|
70
94
|
File.basename(filepath).split('.').first
|
71
95
|
end
|
72
96
|
|
97
|
+
# From a filepath, parse the template inside.
|
98
|
+
# and return the related Tilt instance.
|
99
|
+
# It may return the exception if the template is invalid
|
100
|
+
# (only for HAML templates).
|
101
|
+
#
|
102
|
+
# @param [ String ] filepath The path to the file
|
103
|
+
#
|
104
|
+
# @return [ Object ] The Tilt template or the exception itself if the template is invalid
|
105
|
+
#
|
106
|
+
def fetch_template(filepath)
|
107
|
+
begin
|
108
|
+
Tilt.new(filepath)
|
109
|
+
rescue Haml::SyntaxError => e
|
110
|
+
e
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
73
114
|
end
|
74
115
|
|
75
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_mounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01
|
12
|
+
date: 2013-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -471,7 +471,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
471
471
|
version: '0'
|
472
472
|
segments:
|
473
473
|
- 0
|
474
|
-
hash: -
|
474
|
+
hash: -4090664391938544491
|
475
475
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
476
476
|
none: false
|
477
477
|
requirements:
|