nanoc-conref-fs 0.4.4 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbf03675daecb4694ef342f40682105c08117466
4
- data.tar.gz: b654f9aec04cb0b670be30f8a292bca44f154c79
3
+ metadata.gz: 35dc702fdbe8ffa00711be829afcf827fe5565fe
4
+ data.tar.gz: 83767a5ade9f4945c99f25d3a03122e1ff3467e7
5
5
  SHA512:
6
- metadata.gz: 21894f1ea9a1a74fdf32f0b8030687d424716bf8feae45fb0f9f8c965bdc0651de8ebd224337d3ac9d015f4c1b35b873bd831c1058692a510555208456a39001
7
- data.tar.gz: 9d272820c3cc481104c5da4083e988b293335776fd595d453b5c0a83f575192d588f7a03eae571101136d23514feb196754b334fd89fa7ac339f416c4580be0c
6
+ metadata.gz: bf4dd287a13d192f38777a6dc31211976ba3e6398ce7b9f53a06769740086dc706217788e05b1a954c35425863b75a41bea4937eaaa801eef7a2c87487b56289
7
+ data.tar.gz: 37c643e5e0b2ac33cb40aa87025146d3549aad0d48f7215ce4cbb5f41aa79a65f2580104e4ae78fd7a54343fe5c466b1a6eb70a657e10d83b0c6b98256d69d62
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in jekyll-html-pipeline.gemspec
4
3
  gemspec
@@ -158,44 +158,41 @@ class ConrefFS < Nanoc::DataSource
158
158
  end
159
159
 
160
160
  begin
161
- result = ''
162
- # This pass replaces any conditionals
163
- result = if content =~ Conrefifier::BLOCK_SUB
164
- content.gsub(Conrefifier::BLOCK_SUB) do |match|
165
- Conrefifier.apply_liquid(match, page_vars).chomp
166
- end
167
- else
168
- content
169
- end
170
-
171
- # This pass converts the frontmatter variables,
172
- # and inserts data variables into the body
173
- if result =~ Conrefifier::SINGLE_SUB
174
- result = result.gsub(Conrefifier::SINGLE_SUB) do |match|
175
- resolution = Conrefifier.apply_liquid(match, page_vars).strip
176
- if resolution.start_with?('*')
177
- if resolution[1] != '*'
178
- resolution = resolution.sub(/\*(.+?)\*/, '<em>\1</em>')
179
- else
180
- resolution = resolution.sub(/\*{2}(.+?)\*{2}/, '<strong>\1</strong>')
181
- end
182
- end
183
- resolution
184
- end
161
+ result = content
162
+
163
+ # This pass replaces any matched conditionals
164
+ if result =~ Conrefifier::BLOCK_SUB || result =~ Conrefifier::SINGLE_SUB
165
+ result = Conrefifier.apply_liquid(result, page_vars)
185
166
  end
186
167
 
187
168
  # This second pass renders any previously inserted
188
- # data conditionals within the body
169
+ # data conditionals within the body. If a Liquid parse
170
+ # returns a blank string, we'll return the original
189
171
  if result =~ Conrefifier::SINGLE_SUB
190
172
  result = result.gsub(Conrefifier::SINGLE_SUB) do |match|
191
- Conrefifier.apply_liquid(match, page_vars)
173
+ liquified = Conrefifier.apply_liquid(match, page_vars)
174
+ liquified.empty? ? match : liquified
175
+ end
176
+ end
177
+
178
+ # This converts ": *" frontmatter strings into HTML equivalents;
179
+ # otherwise, ": *" messes the YAML parsing
180
+ result = result.gsub(/\A---\s*\n(.*?\n?)^---\s*$\n?/m) do |frontmatter|
181
+ frontmatter.gsub(/:\s*(\*.+)/) do |_|
182
+ asterisk_match = Regexp.last_match[1]
183
+ if asterisk_match[1] != '*'
184
+ asterisk_match = asterisk_match.sub(/\*(.+?)\*/, ': <em>\1</em>')
185
+ else
186
+ asterisk_match = asterisk_match.sub(/\*{2}(.+?)\*{2}/, ': <strong>\1</strong>')
187
+ end
188
+ asterisk_match
192
189
  end
193
190
  end
194
191
 
195
192
  result
196
- rescue Liquid::SyntaxError
193
+ rescue Liquid::SyntaxError => e
197
194
  # unrecognized Liquid, so just return the content
198
- # STDERR.puts "Could not convert #{filename}: #{e.message}"
195
+ STDERR.puts "Could not convert #{filename}: #{e.message}"
199
196
  result
200
197
  rescue => e
201
198
  raise "#{e.message}: #{e.inspect}"
@@ -18,6 +18,6 @@ module Conrefifier
18
18
 
19
19
  def self.apply_liquid(content, data_vars)
20
20
  data_vars['page'] = data_vars[:page].stringify_keys
21
- ::Liquid::Template.parse(content).render(data_vars)
21
+ Liquid::Template.parse(content, :error_mode => :warn).render(data_vars)
22
22
  end
23
23
  end
@@ -1,11 +1,9 @@
1
1
  lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'nanoc-conref-fs/version'
5
-
6
4
  Gem::Specification.new do |spec|
7
5
  spec.name = 'nanoc-conref-fs'
8
- spec.version = Conrefifier::VERSION
6
+ spec.version = '0.5.0'
9
7
  spec.authors = ['Garen Torikian']
10
8
  spec.email = ['gjtorikian@gmail.com']
11
9
  spec.summary = 'A Nanoc filesystem to permit using conrefs/reusables in your content.'
@@ -212,4 +212,30 @@ class DatafilesTest < MiniTest::Test
212
212
  assert_equal output_file, test_file
213
213
  end
214
214
  end
215
+
216
+ def test_raw_tags
217
+ with_site(name: FIXTURES_DIR) do |site|
218
+
219
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
220
+ site.compile
221
+
222
+ output_file = read_output_file('liquid', 'raw')
223
+ test_file = read_test_file('liquid', 'raw')
224
+
225
+ assert_equal output_file, test_file
226
+ end
227
+ end
228
+
229
+ def test_multiple_version_blocks
230
+ with_site(name: FIXTURES_DIR) do |site|
231
+
232
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
233
+ site.compile
234
+
235
+ output_file = read_output_file('liquid', 'multiple_versions')
236
+ test_file = read_test_file('liquid', 'multiple_versions')
237
+
238
+ assert_equal output_file, test_file
239
+ end
240
+ end
215
241
  end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Multiples
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ Hi I am 2.0.
12
+
13
+ Hi I am tiny.
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: Multiples
3
+ ---
4
+
5
+ {% if page.version > 2.0 %}
6
+
7
+ Hi I am 2.0.
8
+
9
+ {% if page.version > 2.3 %}
10
+
11
+ Hi I am 2.3.
12
+
13
+ {% else %}
14
+
15
+ Hi I am tiny.
16
+
17
+ {% endif %}
18
+
19
+ {% endif %}
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Raw
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ For example, to list a project's name, you might write something like `The project is called {{ site.github.project_title }}` or to list an organization's open source repositories, you might use the following:
12
+
13
+ ``` liquid
14
+ {% for repository in site.github.public_repositories %}
15
+ * [{{ repository.name }}]({{ repository.html_url }})
16
+ {% endfor %}
17
+ ```
18
+
19
+ </body>
20
+ </html>
@@ -0,0 +1,15 @@
1
+ ---
2
+ title: Raw
3
+ ---
4
+
5
+ For example, to list a project's name, you might write something like `The project is called {% raw %}{{ site.github.project_title }}{% endraw %}` or to list an organization's open source repositories, you might use the following:
6
+
7
+ {% raw %}
8
+
9
+ ``` liquid
10
+ {% for repository in site.github.public_repositories %}
11
+ * [{{ repository.name }}]({{ repository.html_url }})
12
+ {% endfor %}
13
+ ```
14
+
15
+ {% endraw %}
@@ -31,6 +31,11 @@ page_variables:
31
31
  path: "different"
32
32
  values:
33
33
  version: "2.0"
34
+ -
35
+ scope:
36
+ path: "multiple_versions"
37
+ values:
38
+ version: 2.2
34
39
 
35
40
  string_pattern_type: glob
36
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-conref-fs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nanoc
@@ -111,7 +111,6 @@ files:
111
111
  - lib/nanoc-conref-fs/conref-fs.rb
112
112
  - lib/nanoc-conref-fs/conrefifier.rb
113
113
  - lib/nanoc-conref-fs/datafiles.rb
114
- - lib/nanoc-conref-fs/version.rb
115
114
  - nanoc-conref-fs.gemspec
116
115
  - script/bootstrap
117
116
  - test/conref_fs_test.rb
@@ -135,6 +134,10 @@ files:
135
134
  - test/fixtures/content/frontmatter/different.md
136
135
  - test/fixtures/content/frontmatter/title.html
137
136
  - test/fixtures/content/frontmatter/title.md
137
+ - test/fixtures/content/liquid/multiple_versions.html
138
+ - test/fixtures/content/liquid/multiple_versions.md
139
+ - test/fixtures/content/liquid/raw.html
140
+ - test/fixtures/content/liquid/raw.md
138
141
  - test/fixtures/content/maliciousness/asterisk_double.html
139
142
  - test/fixtures/content/maliciousness/asterisk_double.md
140
143
  - test/fixtures/content/maliciousness/asterisk_single.html
@@ -213,6 +216,10 @@ test_files:
213
216
  - test/fixtures/content/frontmatter/different.md
214
217
  - test/fixtures/content/frontmatter/title.html
215
218
  - test/fixtures/content/frontmatter/title.md
219
+ - test/fixtures/content/liquid/multiple_versions.html
220
+ - test/fixtures/content/liquid/multiple_versions.md
221
+ - test/fixtures/content/liquid/raw.html
222
+ - test/fixtures/content/liquid/raw.md
216
223
  - test/fixtures/content/maliciousness/asterisk_double.html
217
224
  - test/fixtures/content/maliciousness/asterisk_double.md
218
225
  - test/fixtures/content/maliciousness/asterisk_single.html
@@ -1,3 +0,0 @@
1
- module Conrefifier
2
- VERSION = '0.4.4'
3
- end