bridgetown-core 0.9.0 → 0.10.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
  SHA256:
3
- metadata.gz: d54c0a2a041830e819a8f60b45164f00fa833bc5d795941599969bb967e550ae
4
- data.tar.gz: 81bf01e9efec7ea134d9c76de18a0b19bdd4d9addc7d0011a03fc038d18890f3
3
+ metadata.gz: 9ceaadbfc504f5ac87f7ffbca7b5b87ed2967f564a12ca69f577f9d3a5216cf4
4
+ data.tar.gz: be1d543b08eb98d7e02f7f0eb00d0e31d112363601f716956e140e1949f09d8e
5
5
  SHA512:
6
- metadata.gz: 8746742cc41353b34c8f91549b1981034014fb35cb23ea4b3077b96c9c41ca10470e688c78b106b1d7b1655ca0503e01e9095bcc0f17ac3afdc8aadd891f49f9
7
- data.tar.gz: 50c6e804f3712ab3a30fafddbde9c5a0c9c04487b8a3f671fb9bc8cdd1d5fb14b64913b0f048672592ef15fad8d2c5aad1e0f3c348c6fce5479fdfa13f718aa2
6
+ metadata.gz: 9e7b7feb4ee52314b2ca52893c22484e2419f0af871519e8f5417b04cc8dce91bf1b65931a993b0ae46c7c62a7ee77fabd8c210ec2f1cac4b21af6ce6d14a22e
7
+ data.tar.gz: c4e9971e2887f3c2490c21a7207d684fa6c8194e5c27b7a375f81a7aca79d0b42632f96b7a6762e25c6749be22976cba84c234d2b176d92082f342c5e8465369
@@ -69,6 +69,9 @@ module Bridgetown
69
69
  #
70
70
  # Happy Bridgetowning!
71
71
 
72
+ # Pull in latest Liquid from Shopify with new Render tag
73
+ gem 'liquid', "> 4.0.3", github: "jaredcwhite/liquid"
74
+
72
75
  gem "bridgetown", "~> #{Bridgetown::VERSION}"
73
76
 
74
77
  RUBY
@@ -14,6 +14,7 @@ module Bridgetown
14
14
  "cache_dir" => ".bridgetown-cache",
15
15
  "layouts_dir" => "_layouts",
16
16
  "data_dir" => "_data",
17
+ "components_dir" => "_components",
17
18
  "includes_dir" => "_includes",
18
19
  "collections" => {},
19
20
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "liquid_renderer/file_system"
3
4
  require_relative "liquid_renderer/file"
4
5
  require_relative "liquid_renderer/table"
5
6
 
@@ -11,6 +12,12 @@ module Bridgetown
11
12
 
12
13
  def initialize(site)
13
14
  @site = site
15
+
16
+ # Set up Liquid file system access to components for the Render tag
17
+ Liquid::Template.file_system = LiquidRenderer::FileSystem.new(
18
+ @site.components_load_paths, "%s.liquid"
19
+ )
20
+
14
21
  Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
15
22
  reset
16
23
  end
@@ -10,7 +10,12 @@ module Bridgetown
10
10
 
11
11
  def parse(content)
12
12
  measure_time do
13
- @renderer.cache[@filename] ||= Liquid::Template.parse(content, line_numbers: true)
13
+ # Remove extraneous indentation for rendercontent tags
14
+ processed_content = content.gsub(%r!^[ \t]+{%-? rendercontent!, "{% rendercontent")
15
+
16
+ @renderer.cache[@filename] ||= Liquid::Template.parse(
17
+ processed_content, line_numbers: true
18
+ )
14
19
  end
15
20
  @template = @renderer.cache[@filename]
16
21
 
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ class LiquidRenderer
5
+ class FileSystem < Liquid::LocalFileSystem
6
+ def read_template_file(template_path)
7
+ load_paths = root
8
+ found_paths = []
9
+
10
+ load_paths.each do |load_path|
11
+ # Use Liquid's gut checks to verify template pathname
12
+ self.root = load_path
13
+ full_template_path = full_path(template_path)
14
+
15
+ # Look for .liquid as well as .html extensions
16
+ path_variants = [
17
+ Pathname.new(full_template_path),
18
+ Pathname.new(full_template_path).sub_ext(".html"),
19
+ ]
20
+
21
+ found_paths << path_variants.find(&:exist?)
22
+ end
23
+
24
+ # Restore pristine state
25
+ self.root = load_paths
26
+
27
+ found_paths.compact!
28
+
29
+ raise Liquid::FileSystemError, "No such template '#{template_path}'" if found_paths.empty?
30
+
31
+ # Last path in the list wins
32
+ ::File.read(found_paths.last)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -10,7 +10,8 @@ module Bridgetown
10
10
  :plugin_manager
11
11
 
12
12
  attr_accessor :converters, :generators, :reader
13
- attr_reader :regenerator, :liquid_renderer, :includes_load_paths
13
+ attr_reader :regenerator, :liquid_renderer, :components_load_paths,
14
+ :includes_load_paths
14
15
 
15
16
  # Public: Initialize a new Site.
16
17
  #
@@ -52,6 +53,7 @@ module Bridgetown
52
53
 
53
54
  configure_cache
54
55
  configure_plugins
56
+ configure_component_paths
55
57
  configure_include_paths
56
58
  configure_file_read_opts
57
59
 
@@ -435,6 +437,20 @@ module Bridgetown
435
437
  self.plugins = plugin_manager.plugins_path
436
438
  end
437
439
 
440
+ def configure_component_paths
441
+ @components_load_paths = config["components_dir"].then do |dir|
442
+ dir.is_a?(Array) ? dir : [dir]
443
+ end
444
+ @components_load_paths.map! do |dir|
445
+ if !!(dir =~ %r!^\.\.?\/!)
446
+ # allow ./dir or ../../dir type options
447
+ File.expand_path(dir.to_s, root_dir)
448
+ else
449
+ in_source_dir(dir.to_s)
450
+ end
451
+ end
452
+ end
453
+
438
454
  def configure_include_paths
439
455
  @includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s))
440
456
  end
@@ -99,16 +99,9 @@ module Bridgetown
99
99
 
100
100
  def locate_include_file(context, file)
101
101
  includes_dirs = tag_includes_dirs(context)
102
- # TODO: component folder should be configured separately
103
- if file.start_with?("_components")
104
- first_dir = includes_dirs.first
105
- path = PathManager.join(first_dir.sub(%r!/_includes$!, ""), file)
106
- return path if valid_include_file?(path, first_dir.to_s)
107
- else
108
- includes_dirs.each do |dir|
109
- path = PathManager.join(dir, file)
110
- return path if valid_include_file?(path, dir.to_s)
111
- end
102
+ includes_dirs.each do |dir|
103
+ path = PathManager.join(dir, file)
104
+ return path if valid_include_file?(path, dir.to_s)
112
105
  end
113
106
  raise IOError, could_not_locate_message(file, includes_dirs)
114
107
  end
@@ -184,7 +177,6 @@ module Bridgetown
184
177
 
185
178
  private
186
179
 
187
- # TODO: update this to support components as well
188
180
  def could_not_locate_message(file, includes_dirs)
189
181
  "Could not locate the included file '#{file}' in any of #{includes_dirs}." \
190
182
  " Ensure it exists in one of those directories."
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class BlockRenderTag < Liquid::Block
6
+ def initialize(tag_name, markup, options)
7
+ super
8
+
9
+ @tag = tag_name
10
+ @markup = markup
11
+ @options = options
12
+ end
13
+
14
+ def render(context)
15
+ content = super.gsub(%r!^[ \t]+!, "") # unindent the incoming text
16
+
17
+ site = context.registers[:site]
18
+ converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
19
+ markdownified_content = converter.convert(content)
20
+
21
+ context.stack do
22
+ context["componentcontent"] = markdownified_content
23
+ render_params = "#{@markup}, content: componentcontent"
24
+ render_tag = Liquid::Render.parse("render", render_params, @options, @parse_context)
25
+ render_tag.render_tag(context, +"")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ Liquid::Template.register_tag("rendercontent", Bridgetown::Tags::BlockRenderTag)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-16 00:00:00.000000000 Z
11
+ date: 2020-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -236,6 +236,7 @@ files:
236
236
  - lib/bridgetown-core/liquid_extensions.rb
237
237
  - lib/bridgetown-core/liquid_renderer.rb
238
238
  - lib/bridgetown-core/liquid_renderer/file.rb
239
+ - lib/bridgetown-core/liquid_renderer/file_system.rb
239
240
  - lib/bridgetown-core/liquid_renderer/table.rb
240
241
  - lib/bridgetown-core/log_adapter.rb
241
242
  - lib/bridgetown-core/log_writer.rb
@@ -258,11 +259,11 @@ files:
258
259
  - lib/bridgetown-core/renderer.rb
259
260
  - lib/bridgetown-core/site.rb
260
261
  - lib/bridgetown-core/static_file.rb
261
- - lib/bridgetown-core/tags/component.rb
262
262
  - lib/bridgetown-core/tags/highlight.rb
263
263
  - lib/bridgetown-core/tags/include.rb
264
264
  - lib/bridgetown-core/tags/link.rb
265
265
  - lib/bridgetown-core/tags/post_url.rb
266
+ - lib/bridgetown-core/tags/render_content.rb
266
267
  - lib/bridgetown-core/url.rb
267
268
  - lib/bridgetown-core/utils.rb
268
269
  - lib/bridgetown-core/utils/ansi.rb
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Tags
5
- class BlockComponentTag < Liquid::Block
6
- def initialize(tag_name, markup, tokens)
7
- super
8
-
9
- filename, @extra_params = markup.strip.split(" ", 2)
10
- @component_path = "_components/#{filename.strip}.html"
11
-
12
- @tag_name = tag_name
13
- end
14
-
15
- def render(context)
16
- markdown_content = super
17
-
18
- site = context.registers[:site]
19
- converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
20
- markdownified_content = converter.convert(markdown_content)
21
-
22
- context.stack do
23
- context["componentcontent"] = markdownified_content
24
- include_params = "#{@component_path} content=componentcontent"
25
- include_params = "#{include_params} #{@extra_params}" if @extra_params
26
- include_tag = IncludeTag.parse("include", include_params, [], @parse_context)
27
- include_tag.render(context)
28
- end
29
- end
30
- end
31
- end
32
- end
33
-
34
- Liquid::Template.register_tag("component", Bridgetown::Tags::BlockComponentTag)