bridgetown-core 0.19.0 → 0.21.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bridgetown +6 -0
- data/bridgetown-core.gemspec +3 -4
- data/lib/bridgetown-core.rb +34 -12
- data/lib/bridgetown-core/cleaner.rb +7 -1
- data/lib/bridgetown-core/collection.rb +176 -77
- data/lib/bridgetown-core/commands/apply.rb +4 -3
- data/lib/bridgetown-core/commands/base.rb +9 -0
- data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
- data/lib/bridgetown-core/commands/configure.rb +66 -0
- data/lib/bridgetown-core/commands/console.rb +4 -0
- data/lib/bridgetown-core/commands/new.rb +8 -0
- data/lib/bridgetown-core/commands/plugins.rb +1 -0
- data/lib/bridgetown-core/component.rb +178 -0
- data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
- data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
- data/lib/bridgetown-core/concerns/site/content.rb +56 -15
- data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
- data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
- data/lib/bridgetown-core/concerns/validatable.rb +1 -4
- data/lib/bridgetown-core/configuration.rb +49 -28
- data/lib/bridgetown-core/configurations/.keep +0 -0
- data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
- data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
- data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
- data/lib/bridgetown-core/configurations/netlify.rb +6 -0
- data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
- data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
- data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
- data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
- data/lib/bridgetown-core/configurations/swup.rb +37 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
- data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
- data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
- data/lib/bridgetown-core/configurations/turbo.rb +16 -0
- data/lib/bridgetown-core/converter.rb +23 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +50 -41
- data/lib/bridgetown-core/converters/identity.rb +0 -9
- data/lib/bridgetown-core/converters/markdown.rb +14 -4
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +3 -0
- data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
- data/lib/bridgetown-core/current.rb +10 -0
- data/lib/bridgetown-core/document.rb +6 -14
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/page_drop.rb +4 -0
- data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
- data/lib/bridgetown-core/drops/site_drop.rb +33 -8
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
- data/lib/bridgetown-core/entry_filter.rb +10 -23
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters.rb +3 -2
- data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
- data/lib/bridgetown-core/generator.rb +2 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
- data/lib/bridgetown-core/helpers.rb +48 -9
- data/lib/bridgetown-core/layout.rb +28 -13
- data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
- data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
- data/lib/bridgetown-core/model/base.rb +138 -0
- data/lib/bridgetown-core/model/builder_origin.rb +40 -0
- data/lib/bridgetown-core/model/origin.rb +38 -0
- data/lib/bridgetown-core/model/repo_origin.rb +126 -0
- data/lib/bridgetown-core/page.rb +9 -1
- data/lib/bridgetown-core/plugin.rb +2 -26
- data/lib/bridgetown-core/plugin_manager.rb +0 -2
- data/lib/bridgetown-core/publisher.rb +7 -1
- data/lib/bridgetown-core/reader.rb +26 -13
- data/lib/bridgetown-core/readers/data_reader.rb +3 -4
- data/lib/bridgetown-core/readers/post_reader.rb +1 -1
- data/lib/bridgetown-core/regenerator.rb +8 -1
- data/lib/bridgetown-core/related_posts.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +6 -13
- data/lib/bridgetown-core/resource/base.rb +317 -0
- data/lib/bridgetown-core/resource/destination.rb +49 -0
- data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
- data/lib/bridgetown-core/resource/relations.rb +132 -0
- data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
- data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
- data/lib/bridgetown-core/resource/transformer.rb +175 -0
- data/lib/bridgetown-core/ruby_template_view.rb +12 -4
- data/lib/bridgetown-core/site.rb +9 -1
- data/lib/bridgetown-core/static_file.rb +33 -10
- data/lib/bridgetown-core/url.rb +1 -0
- data/lib/bridgetown-core/utils.rb +48 -41
- data/lib/bridgetown-core/utils/platforms.rb +1 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +1 -1
- data/lib/site_template/README.md +70 -0
- data/lib/site_template/package.json.erb +2 -2
- data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
- data/lib/site_template/webpack.config.js.erb +26 -6
- metadata +55 -39
- data/lib/bridgetown-core/page_without_a_file.rb +0 -17
- data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
- data/lib/bridgetown-core/utils/exec.rb +0 -26
- data/lib/bridgetown-core/utils/internet.rb +0 -37
- data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Taken from https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values
|
3
|
+
|
4
|
+
echo "Updating netlify.toml with references to our built files"
|
5
|
+
|
6
|
+
CSS_PATH=`find output/_bridgetown/static/css/*.css -type f | sed -e 's,output\/,/,g'`
|
7
|
+
JS_PATH=`find output/_bridgetown/static/js/*.js -type f | sed -e 's,output\/,/,g'`
|
8
|
+
|
9
|
+
echo "CSS Path: ${CSS_PATH}"
|
10
|
+
echo "JS Path: ${JS_PATH}"
|
11
|
+
|
12
|
+
sed -i s,CSS_PATH,${CSS_PATH},g netlify.toml
|
13
|
+
sed -i s,JS_PATH,${JS_PATH},g netlify.toml
|
14
|
+
sed -i s,NETLIFY_IMAGES_CDN_DOMAIN,${NETLIFY_IMAGES_CDN_DOMAIN},g netlify.toml
|
@@ -0,0 +1,44 @@
|
|
1
|
+
[build]
|
2
|
+
command = "yarn deploy && ./bin/netlify.sh"
|
3
|
+
publish = "output"
|
4
|
+
|
5
|
+
[build.environment]
|
6
|
+
NODE_ENV = "development"
|
7
|
+
BRIDGETOWN_ENV = "production"
|
8
|
+
|
9
|
+
[build.processing]
|
10
|
+
skip_processing = false
|
11
|
+
[build.processing.css]
|
12
|
+
bundle = false
|
13
|
+
minify = true
|
14
|
+
[build.processing.js]
|
15
|
+
bundle = false
|
16
|
+
minify = true
|
17
|
+
[build.processing.html]
|
18
|
+
pretty_urls = true
|
19
|
+
[build.processing.images]
|
20
|
+
compress = true
|
21
|
+
|
22
|
+
[[headers]]
|
23
|
+
for = "*"
|
24
|
+
[headers.values]
|
25
|
+
X-Frame-Options = "DENY"
|
26
|
+
X-XSS-Protection = "1; mode=block"
|
27
|
+
X-Content-Type-Options = "nosniff"
|
28
|
+
Strict-Transport-Security = "max-age=15552000; includeSubDomains"
|
29
|
+
Referrer-Policy = "no-referrer-when-downgrade"
|
30
|
+
Cache-Control = "public, max-age=604800, s-max-age=604800"
|
31
|
+
|
32
|
+
[[headers]]
|
33
|
+
for = "/"
|
34
|
+
[headers.values]
|
35
|
+
Link = [
|
36
|
+
"<CSS_PATH>; rel=preload; as=style",
|
37
|
+
"<JS_PATH>; rel=preload; as=script",
|
38
|
+
"<https://NETLIFY_IMAGES_CDN_DOMAIN>; rel=preconnect"
|
39
|
+
]
|
40
|
+
|
41
|
+
[[headers]]
|
42
|
+
for = "/*.(png|jpg|js|css|svg|woff|ttf|eot|ico|woff2)"
|
43
|
+
[headers.values]
|
44
|
+
Cache-Control = "public, max-age=31536000, s-max-age=31536000"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
say_status :purgecss, "Installing PurgeCSS"
|
6
|
+
|
7
|
+
run "yarn add -D purgecss"
|
8
|
+
|
9
|
+
create_builder "purgecss_builder.rb" do
|
10
|
+
<<~RUBY
|
11
|
+
class PurgeCSS < SiteBuilder
|
12
|
+
def build
|
13
|
+
unless config[:watch] # don't run in "watch mode"
|
14
|
+
hook :site, :post_write do
|
15
|
+
purgecss_file = site.in_root_dir("purgecss.config.js")
|
16
|
+
unless File.exist?(purgecss_file)
|
17
|
+
config_js = <<~PURGE
|
18
|
+
module.exports = {
|
19
|
+
content: ['frontend/javascript/*.js','./output/**/*.html'],
|
20
|
+
output: "./output/_bridgetown/static/css"
|
21
|
+
}
|
22
|
+
PURGE
|
23
|
+
File.write(purgecss_file, config_js.strip)
|
24
|
+
end
|
25
|
+
manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
|
26
|
+
if File.exist?(manifest_file)
|
27
|
+
manifest = JSON.parse(File.read(manifest_file))
|
28
|
+
css_file = manifest["main.css"].split("/").last
|
29
|
+
css_path = ["output", "_bridgetown", "static", "css", css_file].join("/")
|
30
|
+
Bridgetown.logger.info "PurgeCSS", "Purging \#{css_file}"
|
31
|
+
oldsize = File.stat(css_path).size / 1000
|
32
|
+
system "./node_modules/.bin/purgecss -c purgecss.config.js -css \#{css_path}"
|
33
|
+
newsize = File.stat(css_path).size / 1000
|
34
|
+
if newsize < oldsize
|
35
|
+
Bridgetown.logger.info "PurgeCSS", "Done! File size reduced from \#{oldsize}kB to \#{newsize}kB"
|
36
|
+
else
|
37
|
+
Bridgetown.logger.info "PurgeCSS", "Done. No apparent change in file size (\#{newsize}kB)."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
RUBY
|
45
|
+
end
|
46
|
+
|
47
|
+
say_status :purgecss, "All set! Open plugins/builders/purgecss_builder.rb if you'd like to customize the PurgeCSS config."
|
48
|
+
|
49
|
+
# rubocop:enable all
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
say "Installing Stimulus...", :green
|
6
|
+
|
7
|
+
run("yarn add stimulus")
|
8
|
+
|
9
|
+
say 'Adding Stimulus to "frontend/javascript/index.js"...', :magenta
|
10
|
+
|
11
|
+
javascript_import do
|
12
|
+
<<~JS
|
13
|
+
import { Application } from "stimulus"
|
14
|
+
import { definitionsFromContext } from "stimulus/webpack-helpers"
|
15
|
+
JS
|
16
|
+
end
|
17
|
+
|
18
|
+
javascript_dir = File.join("frontend", "javascript")
|
19
|
+
|
20
|
+
append_to_file(File.join(javascript_dir, "index.js")) do
|
21
|
+
<<~JS
|
22
|
+
const application = Application.start()
|
23
|
+
const context = require.context("./controllers", true, /\.js$/)
|
24
|
+
application.load(definitionsFromContext(context))
|
25
|
+
JS
|
26
|
+
end
|
27
|
+
|
28
|
+
controller_dir = File.join(javascript_dir, "controllers")
|
29
|
+
|
30
|
+
say "Creating a `./#{controller_dir}` directory...", :magenta
|
31
|
+
FileUtils.mkdir_p(controller_dir)
|
32
|
+
|
33
|
+
say "Creating an example Stimulus Controller for you!...", :magenta
|
34
|
+
create_file(File.join(controller_dir, "example_controller.js")) do
|
35
|
+
<<~JS
|
36
|
+
import { Controller } from "stimulus"
|
37
|
+
export default class extends Controller {
|
38
|
+
connect() {
|
39
|
+
console.log("Hello, Stimulus!", this.element)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
JS
|
43
|
+
end
|
44
|
+
|
45
|
+
say "Stimulus successfully added", :green
|
46
|
+
|
47
|
+
say "To start adding controllers, visit the `./frontend/javascript/controllers/` directory", :blue
|
48
|
+
say "Make sure your controllers follow the `[name]_controller.js` convention", :blue
|
49
|
+
say 'For further reading, check out "https://stimulus.hotwire.dev/"', :blue
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
packages = "swup @swup/body-class-plugin @swup/scroll-plugin @swup/fade-theme"
|
6
|
+
say_status :swup, "Adding the following yarn packages: #{packages}"
|
7
|
+
system("yarn add #{packages}")
|
8
|
+
|
9
|
+
javascript_import do
|
10
|
+
<<~JS
|
11
|
+
import Swup from "swup"
|
12
|
+
import SwupBodyClassPlugin from "@swup/body-class-plugin"
|
13
|
+
import SwupScrollPlugin from "@swup/scroll-plugin"
|
14
|
+
import SwupFadeTheme from "@swup/fade-theme"
|
15
|
+
const swup = new Swup({
|
16
|
+
plugins: [
|
17
|
+
new SwupBodyClassPlugin(),
|
18
|
+
new SwupScrollPlugin(),
|
19
|
+
new SwupFadeTheme(),
|
20
|
+
]
|
21
|
+
})
|
22
|
+
JS
|
23
|
+
end
|
24
|
+
|
25
|
+
css_index = File.exist?(File.expand_path("frontend/styles/index.scss", destination_root)) ? "frontend/styles/index.scss" : "frontend/styles/index.css"
|
26
|
+
append_to_file css_index do
|
27
|
+
<<~CSS
|
28
|
+
.swup-transition-main {
|
29
|
+
transition: opacity .2s;
|
30
|
+
}
|
31
|
+
CSS
|
32
|
+
end
|
33
|
+
|
34
|
+
say_status :swup, "All done! Edit .swup-transition-main in #{css_index} if you wish to adjust the transition animation"
|
35
|
+
say_status :swup, "Make sure you add id=\"swup\" to the primary container of your HTML layout (perhaps <main>)"
|
36
|
+
|
37
|
+
# rubocop:enable all
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
|
6
|
+
|
7
|
+
begin
|
8
|
+
find_in_source_paths("postcss.config.js")
|
9
|
+
rescue Thor::Error
|
10
|
+
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
11
|
+
|
12
|
+
@logger.error "\nError:".red, "🚨 #{error_message}"
|
13
|
+
@logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
|
14
|
+
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
run "yarn add -D tailwindcss"
|
19
|
+
run "npx tailwindcss init"
|
20
|
+
|
21
|
+
remove_file "postcss.config.js"
|
22
|
+
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
|
23
|
+
|
24
|
+
prepend_to_file "frontend/styles/index.css",
|
25
|
+
File.read("#{TEMPLATE_PATH}/css_imports.css")
|
26
|
+
|
27
|
+
run "bundle exec bridgetown configure purgecss"
|
28
|
+
|
29
|
+
# rubocop:enable all
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
say "Installing Turbo...", :green
|
4
|
+
|
5
|
+
run("yarn add @hotwired/turbo")
|
6
|
+
|
7
|
+
say 'Adding Turbo to "frontend/javascript/index.js"...', :magenta
|
8
|
+
|
9
|
+
javascript_import do
|
10
|
+
<<~JS
|
11
|
+
import Turbo from "@hotwired/turbo"
|
12
|
+
JS
|
13
|
+
end
|
14
|
+
|
15
|
+
say "Turbo successfully added", :green
|
16
|
+
say 'For further reading, check out "https://turbo.hotwire.dev/"', :blue
|
@@ -23,6 +23,16 @@ module Bridgetown
|
|
23
23
|
@config = config
|
24
24
|
end
|
25
25
|
|
26
|
+
# Logic to do the content conversion.
|
27
|
+
#
|
28
|
+
# @param content [String] content of file (without front matter).
|
29
|
+
# @param convertible [Bridgetown::Document, Bridgetown::Layout, Bridgetown::Resource::Base]
|
30
|
+
#
|
31
|
+
# @return [String] the converted content.
|
32
|
+
def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument
|
33
|
+
content
|
34
|
+
end
|
35
|
+
|
26
36
|
# Does the given extension match this converter's list of acceptable extensions?
|
27
37
|
#
|
28
38
|
# @param [String] ext
|
@@ -42,5 +52,18 @@ module Bridgetown
|
|
42
52
|
def output_ext(_ext)
|
43
53
|
".html"
|
44
54
|
end
|
55
|
+
|
56
|
+
def line_start(convertible)
|
57
|
+
if convertible.is_a?(Bridgetown::Resource::Base) &&
|
58
|
+
convertible.model.origin.respond_to?(:front_matter_line_count)
|
59
|
+
convertible.model.origin.front_matter_line_count + 4
|
60
|
+
else
|
61
|
+
1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
"#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>"
|
67
|
+
end
|
45
68
|
end
|
46
69
|
end
|
@@ -3,14 +3,26 @@
|
|
3
3
|
require "tilt/erubi"
|
4
4
|
|
5
5
|
module Bridgetown
|
6
|
-
class
|
7
|
-
def
|
8
|
-
|
6
|
+
class OutputBuffer < ActiveSupport::SafeBuffer
|
7
|
+
def initialize(*)
|
8
|
+
super
|
9
|
+
encode!
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def <<(value)
|
13
|
+
return self if value.nil?
|
14
|
+
|
15
|
+
super(value.to_s)
|
16
|
+
end
|
17
|
+
alias_method :append=, :<<
|
18
|
+
|
19
|
+
def safe_expr_append=(val)
|
20
|
+
return self if val.nil? # rubocop:disable Lint/ReturnInVoidContext
|
21
|
+
|
22
|
+
safe_concat val.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :safe_append=, :safe_concat
|
14
26
|
end
|
15
27
|
|
16
28
|
class ERBEngine < Erubi::Engine
|
@@ -22,24 +34,47 @@ module Bridgetown
|
|
22
34
|
@src << ";" unless code[Erubi::RANGE_LAST] == "\n"
|
23
35
|
end
|
24
36
|
|
37
|
+
def add_text(text)
|
38
|
+
return if text.empty?
|
39
|
+
|
40
|
+
src << bufvar << ".safe_append='"
|
41
|
+
src << text.gsub(%r{['\\]}, '\\\\\&')
|
42
|
+
src << "'.freeze;"
|
43
|
+
end
|
44
|
+
|
25
45
|
# pulled from Rails' ActionView
|
26
46
|
BLOCK_EXPR = %r!\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z!.freeze
|
27
47
|
|
28
48
|
def add_expression(indicator, code)
|
49
|
+
src << bufvar << if (indicator == "==") || @escape
|
50
|
+
".safe_expr_append="
|
51
|
+
else
|
52
|
+
".append="
|
53
|
+
end
|
54
|
+
|
29
55
|
if BLOCK_EXPR.match?(code)
|
30
|
-
src << "
|
56
|
+
src << " " << code
|
31
57
|
else
|
32
|
-
|
58
|
+
src << "(" << code << ");"
|
33
59
|
end
|
34
60
|
end
|
61
|
+
end
|
35
62
|
|
36
|
-
|
37
|
-
def
|
38
|
-
|
63
|
+
module ERBCapture
|
64
|
+
def capture(*args)
|
65
|
+
previous_buffer_state = @_erbout
|
66
|
+
@_erbout = OutputBuffer.new
|
67
|
+
result = yield(*args)
|
68
|
+
result = @_erbout.presence || result
|
69
|
+
@_erbout = previous_buffer_state
|
70
|
+
|
71
|
+
result.is_a?(String) ? ERB::Util.h(result) : result
|
39
72
|
end
|
40
73
|
end
|
41
74
|
|
42
75
|
class ERBView < RubyTemplateView
|
76
|
+
include ERBCapture
|
77
|
+
|
43
78
|
def h(input)
|
44
79
|
Erubi.h(input)
|
45
80
|
end
|
@@ -55,37 +90,10 @@ module Bridgetown
|
|
55
90
|
Tilt::ErubiTemplate.new(
|
56
91
|
site.in_source_dir(site.config[:partials_dir], "#{partial_name}.erb"),
|
57
92
|
outvar: "@_erbout",
|
58
|
-
bufval: "Bridgetown::
|
93
|
+
bufval: "Bridgetown::OutputBuffer.new",
|
59
94
|
engine_class: ERBEngine
|
60
95
|
).render(self, options)
|
61
96
|
end
|
62
|
-
|
63
|
-
def markdownify(input = nil, &block)
|
64
|
-
content = Bridgetown::Utils.reindent_for_markdown(
|
65
|
-
block.nil? ? input.to_s : capture(&block)
|
66
|
-
)
|
67
|
-
converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
|
68
|
-
converter.convert(content).strip
|
69
|
-
end
|
70
|
-
|
71
|
-
def capture(obj = nil, &block)
|
72
|
-
previous_buffer_state = @_erbout
|
73
|
-
@_erbout = ERBBuffer.new
|
74
|
-
|
75
|
-
# For compatibility with ActionView, not used by Bridgetown normally
|
76
|
-
previous_ob_state = @output_buffer
|
77
|
-
@output_buffer = ERBBuffer.new
|
78
|
-
|
79
|
-
result = instance_exec(obj, &block)
|
80
|
-
if @output_buffer != ""
|
81
|
-
# use Rails' ActionView buffer if present
|
82
|
-
result = @output_buffer
|
83
|
-
end
|
84
|
-
@_erbout = previous_buffer_state
|
85
|
-
@output_buffer = previous_ob_state
|
86
|
-
|
87
|
-
result.respond_to?(:html_safe) ? result.html_safe : result
|
88
|
-
end
|
89
97
|
end
|
90
98
|
|
91
99
|
module Converters
|
@@ -107,14 +115,15 @@ module Bridgetown
|
|
107
115
|
|
108
116
|
erb_renderer = Tilt::ErubiTemplate.new(
|
109
117
|
convertible.relative_path,
|
118
|
+
line_start(convertible),
|
110
119
|
outvar: "@_erbout",
|
111
|
-
bufval: "Bridgetown::
|
120
|
+
bufval: "Bridgetown::OutputBuffer.new",
|
112
121
|
engine_class: ERBEngine
|
113
122
|
) { content }
|
114
123
|
|
115
124
|
if convertible.is_a?(Bridgetown::Layout)
|
116
125
|
erb_renderer.render(erb_view) do
|
117
|
-
convertible.current_document_output
|
126
|
+
convertible.current_document_output.html_safe
|
118
127
|
end
|
119
128
|
else
|
120
129
|
erb_renderer.render(erb_view)
|