bridgetown-core 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridgetown-core/commands/new.rb +3 -0
- data/lib/bridgetown-core/configuration.rb +1 -0
- data/lib/bridgetown-core/liquid_renderer.rb +7 -0
- data/lib/bridgetown-core/liquid_renderer/file.rb +6 -1
- data/lib/bridgetown-core/liquid_renderer/file_system.rb +36 -0
- data/lib/bridgetown-core/site.rb +17 -1
- data/lib/bridgetown-core/tags/include.rb +3 -11
- data/lib/bridgetown-core/tags/render_content.rb +32 -0
- data/lib/bridgetown-core/version.rb +1 -1
- metadata +4 -3
- data/lib/bridgetown-core/tags/component.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ceaadbfc504f5ac87f7ffbca7b5b87ed2967f564a12ca69f577f9d3a5216cf4
|
4
|
+
data.tar.gz: be1d543b08eb98d7e02f7f0eb00d0e31d112363601f716956e140e1949f09d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7b7feb4ee52314b2ca52893c22484e2419f0af871519e8f5417b04cc8dce91bf1b65931a993b0ae46c7c62a7ee77fabd8c210ec2f1cac4b21af6ce6d14a22e
|
7
|
+
data.tar.gz: c4e9971e2887f3c2490c21a7207d684fa6c8194e5c27b7a375f81a7aca79d0b42632f96b7a6762e25c6749be22976cba84c234d2b176d92082f342c5e8465369
|
@@ -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
|
-
|
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
|
data/lib/bridgetown-core/site.rb
CHANGED
@@ -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, :
|
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
|
-
|
103
|
-
|
104
|
-
|
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)
|
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.
|
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-
|
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)
|