From b78eb276e7a625d5ea5a001921ea2cf615a0ce40 Mon Sep 17 00:00:00 2001 From: Jared White Date: Fri, 26 Apr 2024 21:57:17 -0700 Subject: [PATCH 1/5] Switch to ERB by default on new sites, config YAML optional --- .../lib/bridgetown-core/collection.rb | 19 +++- .../lib/bridgetown-core/commands/build.rb | 5 +- .../lib/bridgetown-core/commands/new.rb | 28 +++--- .../concerns/site/configurable.rb | 1 + .../lib/bridgetown-core/configuration.rb | 92 ++++--------------- .../configuration/configuration_dsl.rb | 5 +- .../lib/bridgetown-core/log_adapter.rb | 1 - .../lib/bridgetown-core/static_file.rb | 6 +- .../lib/site_template/bridgetown.config.yml | 33 ------- .../lib/site_template/config/initializers.rb | 55 +++++++++-- bridgetown-core/test/helper.rb | 1 - bridgetown-core/test/test_configuration.rb | 88 +----------------- 12 files changed, 103 insertions(+), 231 deletions(-) delete mode 100644 bridgetown-core/lib/site_template/bridgetown.config.yml diff --git a/bridgetown-core/lib/bridgetown-core/collection.rb b/bridgetown-core/lib/bridgetown-core/collection.rb index 1132a6bf8..baa84bc30 100644 --- a/bridgetown-core/lib/bridgetown-core/collection.rb +++ b/bridgetown-core/lib/bridgetown-core/collection.rb @@ -206,10 +206,25 @@ def write? !!metadata.fetch("output", false) end - # Used by Resource's permalink processor + # Used by Resources permalink processors # @return [String] def default_permalink - metadata.fetch("permalink", "/:locale/:collection/:path/") + metadata.fetch("permalink", default_configured_permalink) + end + + # What the configured permalink should be absent of user overrides + # @return [String] + def default_configured_permalink + @default_configured_permalink ||= case label + when "data" + nil + when "posts" + site.config.permalink + when "pages" + "/:locale/:path/" + else + "/:locale/:collection/:path/" + end end # Extract options for this collection from the site configuration. diff --git a/bridgetown-core/lib/bridgetown-core/commands/build.rb b/bridgetown-core/lib/bridgetown-core/commands/build.rb index ae4d2047a..d5835dde3 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/build.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/build.rb @@ -29,7 +29,10 @@ def self.print_startup_message # Build your bridgetown site # Continuously watch if `watch` is set to true in the config. def build - Bridgetown.logger.adjust_verbosity(options) + unless options[:quiet] || + caller_locations.find { _1.to_s.include?("bridgetown-core/commands/start.rb") } + self.class.print_startup_message + end # @type [Bridgetown::Configuration] config_options = configuration_with_overrides( diff --git a/bridgetown-core/lib/bridgetown-core/commands/new.rb b/bridgetown-core/lib/bridgetown-core/commands/new.rb index 2994f910b..f243d1564 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/new.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/new.rb @@ -26,8 +26,8 @@ def self.banner desc: "Comma separated list of bundled configurations to perform" class_option :templates, aliases: "-t", - banner: "liquid|erb|serbea", - desc: "Preferred template engine (defaults to Liquid)" + banner: "erb|serbea|liquid", + desc: "Preferred template engine (defaults to ERB)" class_option :"frontend-bundling", aliases: "-e", banner: "esbuild", @@ -121,12 +121,12 @@ def create_site(new_site_path) copy_file("frontend/styles/syntax-highlighting.css") case options["templates"] - when "erb" - setup_erb_templates when "serbea" setup_serbea_templates - else + when "liquid" setup_liquid_templates + else # default if no option specififed + setup_erb_templates end postcss_option ? configure_postcss : configure_sass @@ -140,29 +140,23 @@ def setup_erb_templates directory "TEMPLATES/erb/_layouts", "src/_layouts" directory "TEMPLATES/erb/_components", "src/_components" directory "TEMPLATES/erb/_partials", "src/_partials" - gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML - permalink: pretty - template_engine: erb - YML end def setup_serbea_templates directory "TEMPLATES/serbea/_layouts", "src/_layouts" directory "TEMPLATES/serbea/_components", "src/_components" directory "TEMPLATES/serbea/_partials", "src/_partials" - gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML - permalink: pretty - template_engine: serbea - YML + gsub_file "config/initializers.rb", %r!template_engine "erb"\n!, <<~RUBY + template_engine "serbea" + RUBY end def setup_liquid_templates directory "TEMPLATES/liquid/_layouts", "src/_layouts" directory "TEMPLATES/liquid/_components", "src/_components" - gsub_file "bridgetown.config.yml", %r!permalink: pretty\n!, <<~YML - permalink: pretty - template_engine: liquid - YML + gsub_file "config/initializers.rb", %r!template_engine "erb"\n!, <<~RUBY + template_engine "liquid" + RUBY end def configure_sass diff --git a/bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb b/bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb index 91e2e6fcd..74c8a6e20 100644 --- a/bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb +++ b/bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb @@ -12,6 +12,7 @@ def config=(config) configure_component_paths configure_file_read_opts + # TODO: see if we can just get rid of this. It's only used by GeneratedPage self.permalink_style = (config["permalink"] || "pretty").to_sym end diff --git a/bridgetown-core/lib/bridgetown-core/configuration.rb b/bridgetown-core/lib/bridgetown-core/configuration.rb index c50cdbe7d..4288c9e07 100644 --- a/bridgetown-core/lib/bridgetown-core/configuration.rb +++ b/bridgetown-core/lib/bridgetown-core/configuration.rb @@ -45,6 +45,7 @@ def initialize(*) "eager_load_paths" => [], "autoloader_collapsed_paths" => [], "additional_watch_paths" => [], + "defaults" => [], # Handling Reading "include" => [".htaccess", "_redirects", ".well-known"], @@ -61,26 +62,19 @@ def initialize(*) "ruby_in_front_matter" => true, # Conversion - "content_engine" => "resource", "markdown" => "kramdown", "highlighter" => "rouge", - # Serving - "port" => "4000", - "host" => "127.0.0.1", - "base_path" => "/", - "show_dir_listing" => false, - # Output Configuration + "base_path" => "/", "available_locales" => [:en], "default_locale" => :en, "prefix_default_locale" => false, - "permalink" => nil, # default is set according to content engine + "permalink" => "pretty", "timezone" => nil, # use the local timezone "quiet" => false, "verbose" => false, - "defaults" => [], "liquid" => { "error_mode" => "warn", @@ -107,10 +101,6 @@ def initialize(*) }, }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze - # TODO: Deprecated. Remove support for _config as well as toml in the next release. - CONFIG_FILE_PREFIXES = %w(bridgetown.config _config).freeze - CONFIG_FILE_EXTS = %w(yml yaml toml).freeze - # @return [Hash] attr_accessor :initializers @@ -208,33 +198,8 @@ def verbose(override = {}) end alias_method :verbose?, :verbose - def safe_load_file(filename) # rubocop:todo Metrics - case File.extname(filename) - when %r!\.toml!i - Deprecator.deprecation_message( - "TOML configurations will no longer be supported in the next version of Bridgetown." \ - "Use initializers or a .yaml config instead." - ) - Bridgetown::Utils::RequireGems.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb) - Tomlrb.load_file(filename) - when %r!\.ya?ml!i - if File.basename(filename, ".*") == "_config" - Deprecator.deprecation_message( - "YAML configurations named `_config.y(a)ml' will no longer be supported in the next " \ - "version of Bridgetown. Rename to `bridgetown.config.yml' instead." - ) - end - if File.extname(filename) == ".yaml" - Deprecator.deprecation_message( - "YAML configurations ending in `.yaml' will no longer be supported in the next " \ - "version of Bridgetown. Rename to use `.yml' extension instead." - ) - end - YAMLParser.load_file(filename) || {} - else - raise ArgumentError, - "No parser for '#{filename}' is available. Use a .y(a)ml file instead." - end + def safe_load_file(filename) + YAMLParser.load_file(filename) || {} rescue Psych::DisallowedClass => e raise "Unable to parse `#{File.basename(filename)}'. #{e.message}" end @@ -257,27 +222,17 @@ def config_files(override) # multiple configs can be specified via command line. config_files = override["config"] if config_files.to_s.empty? - file_lookups = CONFIG_FILE_PREFIXES.map do |prefix| - CONFIG_FILE_EXTS.map do |ext| - Bridgetown.sanitized_path(root_dir(override), "#{prefix}.#{ext}") - end - end.flatten.freeze - - found_file = file_lookups.find do |path| - File.exist?(path) - end - - config_files = found_file || file_lookups.first + config_files = "bridgetown.config.yml" @default_config_file = true end Array(config_files) end - # Public: Read in a list of configuration files and merge with this hash + # Read in a list of configuration files and merge with this hash # - # files - the list of configuration file paths + # @param files [Array] # - # Returns the full configuration, with the defaults overridden by the values in the + # @return [Hash] configuration with the defaults overridden by the values in the # configuration files def read_config_files(files) config = self @@ -298,30 +253,23 @@ def read_config_files(files) config end - # Public: Read configuration and return merged Hash + # Read configuration and return merged Hash # - # file - the path to the YAML file to be read in + # @param file [String] the path to the YAML file to be read in # - # Returns this configuration, overridden by the values in the file + # @return [Hash] def read_config_file(file) file = File.expand_path(file) - next_config = safe_load_file(file) + return {} unless File.exist?(file) + + file_config = safe_load_file(file) - unless next_config.is_a?(Hash) + unless file_config.is_a?(Hash) raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow end Bridgetown.logger.debug "Configuration file:", file - next_config - rescue SystemCallError - if @default_config_file ||= nil - initializers_file = File.join(root_dir, "config", "initializers.rb") - Bridgetown.logger.warn "Configuration file:", "none" unless File.file?(initializers_file) - {} - else - Bridgetown.logger.error "Fatal:", "The configuration file '#{file}' could not be found." - raise LoadError, "The Configuration file '#{file}' could not be found." - end + file_config end # Merge in environment-specific options, if present @@ -393,18 +341,12 @@ def add_default_collections # rubocop:todo all self[:collections][:posts][:output] = true self[:collections][:posts][:sort_direction] ||= "descending" - self[:permalink] = "pretty" if self[:permalink].blank? self[:collections][:pages] = {} unless self[:collections][:pages] self[:collections][:pages][:output] = true - self[:collections][:pages][:permalink] ||= "/:locale/:path/" self[:collections][:data] = {} unless self[:collections][:data] self[:collections][:data][:output] = false - unless self[:collections][:posts][:permalink] - self[:collections][:posts][:permalink] = self[:permalink] - end - self end diff --git a/bridgetown-core/lib/bridgetown-core/configuration/configuration_dsl.rb b/bridgetown-core/lib/bridgetown-core/configuration/configuration_dsl.rb index 869c9b5f2..1feb01bf9 100644 --- a/bridgetown-core/lib/bridgetown-core/configuration/configuration_dsl.rb +++ b/bridgetown-core/lib/bridgetown-core/configuration/configuration_dsl.rb @@ -72,8 +72,9 @@ def roda(&block) @scope.roda_initializers << block end - def timezone(tz) # rubocop:disable Naming/MethodParameterName - Bridgetown.set_timezone(tz) + def timezone(new_timezone) + @data[:timezone] = new_timezone + Bridgetown.set_timezone(new_timezone) end def method_missing(key, *value, &block) # rubocop:disable Style/MissingRespondToMissing diff --git a/bridgetown-core/lib/bridgetown-core/log_adapter.rb b/bridgetown-core/lib/bridgetown-core/log_adapter.rb index d7542ee20..fae6094a0 100644 --- a/bridgetown-core/lib/bridgetown-core/log_adapter.rb +++ b/bridgetown-core/lib/bridgetown-core/log_adapter.rb @@ -43,7 +43,6 @@ def adjust_verbosity(options = {}) self.log_level = :debug end debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s - debug "Bridgetown Version:", Bridgetown::VERSION end # Public: Print a debug message diff --git a/bridgetown-core/lib/bridgetown-core/static_file.rb b/bridgetown-core/lib/bridgetown-core/static_file.rb index cb4a1a7bb..491bca732 100644 --- a/bridgetown-core/lib/bridgetown-core/static_file.rb +++ b/bridgetown-core/lib/bridgetown-core/static_file.rb @@ -166,15 +166,13 @@ def cleaned_relative_path end end - # Applies a similar URL-building technique as Bridgetown::Document that takes + # Applies a similar URL-building technique as resources that takes # the collection's URL template into account. The default URL template can # be overriden in the collection's configuration in bridgetown.config.yml. def url @url ||= begin newly_processed = false - special_posts_case = @collection&.label == "posts" && - site.config.content_engine != "resource" - base = if @collection.nil? || special_posts_case + base = if @collection.nil? cleaned_relative_path else newly_processed = true diff --git a/bridgetown-core/lib/site_template/bridgetown.config.yml b/bridgetown-core/lib/site_template/bridgetown.config.yml deleted file mode 100644 index 05378be44..000000000 --- a/bridgetown-core/lib/site_template/bridgetown.config.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Welcome to Bridgetown! -# -# This config file is for settings that affect your whole site, values -# which you are expected to set up once and rarely edit after that. -# -# A list of all available configuration options can be found here: -# https://www.bridgetownrb.com/docs/configuration/options -# -# For technical reasons, this file is *NOT* reloaded automatically when you use -# `bin/bridgetown start`. If you change this file, please restart the server process. -# -# For reloadable site metadata like title, SEO description, social media -# handles, etc., take a look at `src/_data/site_metadata.yml` -# -# If you need help with YAML syntax, here are some quick references for you: -# https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml -# https://learnxinyminutes.com/docs/yaml/ -# - -url: "" # the base hostname & protocol for your site, e.g. https://example.com - -permalink: pretty - -# Other options you might want to investigate: -# -# base_path: "/" # the subpath of your site, e.g. /blog. If you set this option, -# ensure you use the `relative_url` helper for all links and assets in your HTML. -# If you're using esbuild for frontend assets, edit `esbuild.config.js` to -# update `publicPath`. - -# timezone: America/Los_Angeles -# pagination: -# enabled: true diff --git a/bridgetown-core/lib/site_template/config/initializers.rb b/bridgetown-core/lib/site_template/config/initializers.rb index 7d6f3823f..6669ec6cf 100644 --- a/bridgetown-core/lib/site_template/config/initializers.rb +++ b/bridgetown-core/lib/site_template/config/initializers.rb @@ -1,14 +1,56 @@ +# Welcome to Bridgetown! +# +# This configuration file is for settings which affect your whole site. +# +# For more documentation on using this initializers file, visit: +# https://www.bridgetownrb.com/docs/configuration/initializers/ +# +# A list of all available configuration options can be found here: +# https://www.bridgetownrb.com/docs/configuration/options +# +# For technical reasons, this file is *NOT* reloaded automatically when you use +# `bin/bridgetown start`. If you change this file, please restart the server process. +# +# For reloadable site metadata like title, SEO description, social media +# handles, etc., take a look at `src/_data/site_metadata.yml` + Bridgetown.configure do |config| - # You can configure aspects of your Bridgetown site here instead of using - # `bridgetown.config.yml`. For example: + # The base hostname & protocol for your site, e.g. https://example.com + url "" + + # Available options are `erb` (default), `serbea`, or `liquid` + template_engine "erb" + + # Other options you might want to investigate: + + # See list of timezone values here: + # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones # - # permalink "simple" # timezone "America/Los_Angeles" + + # Add collection pagination features to your site. Documentation here: + # https://www.bridgetownrb.com/docs/content/pagination # - # You can also modify options on the configuration object directly, like so: + # pagination do + # enabled true + # end + + # Configure the permalink style for pages and posts. Custom collections can be + # configured separately under the `collections` key. Documentation here: + # https://www.bridgetownrb.com/docs/content/permalinks # - # config.autoload_paths << "models" + # permalink "simple" + + # Optionally host your site off a path, e.g. /blog. If you set this option, + # ensure you use the `relative_url` helper for all links and assets in your HTML. + # If you're using esbuild for frontend assets, edit `esbuild.config.js` to + # update `publicPath`. # + # base_path "/" + + # You can also modify options on this configuration object directly, like so: + # + # config.autoload_paths << "models" # If you find you're having trouble using the new Fast Refresh feature in development, # you can disable it to force full rebuilds instead: @@ -62,7 +104,4 @@ # init :parse_routes # end # - - # For more documentation on how to configure your site using this initializers file, - # visit: https://edge.bridgetownrb.com/docs/configuration/initializers/ end diff --git a/bridgetown-core/test/helper.rb b/bridgetown-core/test/helper.rb index 68a783ed3..19d841015 100644 --- a/bridgetown-core/test/helper.rb +++ b/bridgetown-core/test/helper.rb @@ -127,7 +127,6 @@ def fixture_site(overrides = {}) end def resources_site(overrides = {}) - overrides["content_engine"] = "resource" overrides["available_locales"] ||= %w[en fr] overrides["plugins_dir"] = resources_root_dir("plugins") new_config = site_configuration(overrides) diff --git a/bridgetown-core/test/test_configuration.rb b/bridgetown-core/test/test_configuration.rb index e8e28aeea..0949750bb 100644 --- a/bridgetown-core/test/test_configuration.rb +++ b/bridgetown-core/test/test_configuration.rb @@ -38,11 +38,9 @@ def default_config_fixture(overrides = {}) "posts" => { "output" => true, "sort_direction" => "descending", - "permalink" => "pretty", }, "pages" => { - "output" => true, - "permalink" => "/:locale/:path/", + "output" => true, }, "data" => { "output" => false, @@ -51,13 +49,6 @@ def default_config_fixture(overrides = {}) assert_equal expected, result["collections"] end - should "NOT backwards-compatibilize" do - assert( - Configuration.from("watch" => true)["watch"], - "Expected the 'watch' key to not be removed." - ) - end - should "allow indifferent access" do result = Configuration.from({}) assert result[:collections][:posts][:output] @@ -146,83 +137,6 @@ def default_config_fixture(overrides = {}) end end - context "#config_files" do - setup do - @config = Configuration[{ - "root_dir" => site_root_dir, - "source" => source_dir, - }] - @no_override = {} - @one_config_file = { "config" => "config.yml" } - @multiple_files = { - "config" => %w(config/site.yml config/deploy.toml configuration.yml), - } - end - - should "always return an array" do - assert @config.config_files(@no_override).is_a?(Array) - assert @config.config_files(@one_config_file).is_a?(Array) - assert @config.config_files(@multiple_files).is_a?(Array) - end - - should "return the default config path if no config files are specified" do - assert_equal [site_root_dir("bridgetown.config.yml")], @config.config_files(@no_override) - end - - should "return .yaml if it exists but .yml does not" do - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.yml")).and_return(false) - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.yaml")).and_return(true) - assert_equal [site_root_dir("bridgetown.config.yaml")], @config.config_files(@no_override) - end - - should "return .yml if both .yml and .yaml exist" do - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.yml")).and_return(true) - assert_equal [site_root_dir("bridgetown.config.yml")], @config.config_files(@no_override) - end - - should "return .toml if that exists" do - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.yml")).and_return(false) - allow(File).to receive(:exist?).with( - site_root_dir("bridgetown.config.yaml") - ).and_return(false) - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.toml")).and_return(true) - assert_equal [site_root_dir("bridgetown.config.toml")], @config.config_files(@no_override) - end - - should "return .yml if both .yml and .toml exist" do - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.yml")).and_return(true) - allow(File).to receive(:exist?).with(site_root_dir("bridgetown.config.toml")).and_return(true) - assert_equal [site_root_dir("bridgetown.config.yml")], @config.config_files(@no_override) - end - - should "return legacy _config.yml if bridgetown.config.EXT isn't present" do - allow(File).to receive(:exist?).with( - site_root_dir("bridgetown.config.yml") - ).and_return(false) - allow(File).to receive(:exist?).with( - site_root_dir("bridgetown.config.yaml") - ).and_return(false) - allow(File).to receive(:exist?).with( - site_root_dir("bridgetown.config.toml") - ).and_return(false) - allow(File).to receive(:exist?).with( - site_root_dir("_config.yml") - ).and_return(true) - assert_equal [site_root_dir("_config.yml")], @config.config_files(@no_override) - end - - should "return the config if given one config file" do - assert_equal %w(config.yml), @config.config_files(@one_config_file) - end - - should "return an array of the config files if given many config files" do - assert_equal( - %w(config/site.yml config/deploy.toml configuration.yml), - @config.config_files(@multiple_files) - ) - end - end - context "#read_config_file" do setup do @config = Configuration[{ "source" => source_dir("empty.yml") }] From c40f4f4a725e8281f89d98507b52b40533928469 Mon Sep 17 00:00:00 2001 From: Jared White Date: Fri, 26 Apr 2024 21:58:29 -0700 Subject: [PATCH 2/5] fix rebase glitch --- bridgetown-core/lib/bridgetown-core/commands/build.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/commands/build.rb b/bridgetown-core/lib/bridgetown-core/commands/build.rb index d5835dde3..ae4d2047a 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/build.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/build.rb @@ -29,10 +29,7 @@ def self.print_startup_message # Build your bridgetown site # Continuously watch if `watch` is set to true in the config. def build - unless options[:quiet] || - caller_locations.find { _1.to_s.include?("bridgetown-core/commands/start.rb") } - self.class.print_startup_message - end + Bridgetown.logger.adjust_verbosity(options) # @type [Bridgetown::Configuration] config_options = configuration_with_overrides( From 44a7dbf6a15711b34cdff9594689357c9752bfa8 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sun, 28 Apr 2024 07:42:17 -0700 Subject: [PATCH 3/5] Major refactor of template engine converters --- bridgetown-core/lib/bridgetown-core.rb | 1 - .../concerns/layout_placeable.rb | 2 +- .../concerns/liquid_renderable.rb | 30 --------------- .../concerns/site/renderable.rb | 34 ++++++++++++++--- .../lib/bridgetown-core/configuration.rb | 1 + .../lib/bridgetown-core/converter.rb | 38 ++++++++++++++----- .../converters/erb_templates.rb | 22 +---------- .../bridgetown-core/converters/identity.rb | 2 +- .../converters/liquid_templates.rb | 20 +--------- .../converters/ruby_templates.rb | 1 + .../converters/serbea_templates.rb | 20 +--------- .../lib/bridgetown-core/generated_page.rb | 1 - bridgetown-core/lib/bridgetown-core/layout.rb | 1 - .../lib/bridgetown-core/resource/base.rb | 1 - bridgetown-core/lib/bridgetown-core/utils.rb | 10 ----- 15 files changed, 65 insertions(+), 119 deletions(-) delete mode 100644 bridgetown-core/lib/bridgetown-core/concerns/liquid_renderable.rb diff --git a/bridgetown-core/lib/bridgetown-core.rb b/bridgetown-core/lib/bridgetown-core.rb index ce5567e97..5777687ea 100644 --- a/bridgetown-core/lib/bridgetown-core.rb +++ b/bridgetown-core/lib/bridgetown-core.rb @@ -90,7 +90,6 @@ module Bridgetown autoload :Layout, "bridgetown-core/layout" autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable" autoload :LayoutReader, "bridgetown-core/readers/layout_reader" - autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable" autoload :Localizable, "bridgetown-core/concerns/localizable" autoload :LiquidRenderer, "bridgetown-core/liquid_renderer" autoload :LogAdapter, "bridgetown-core/log_adapter" diff --git a/bridgetown-core/lib/bridgetown-core/concerns/layout_placeable.rb b/bridgetown-core/lib/bridgetown-core/concerns/layout_placeable.rb index a3bd2f4ce..f6db771d1 100644 --- a/bridgetown-core/lib/bridgetown-core/concerns/layout_placeable.rb +++ b/bridgetown-core/lib/bridgetown-core/concerns/layout_placeable.rb @@ -7,7 +7,7 @@ module LayoutPlaceable # Returns false if the document is an asset file or if the front matter # specifies `layout: none` def place_in_layout? - !(yaml_file? || no_layout?) + no_layout?.! end def no_layout? diff --git a/bridgetown-core/lib/bridgetown-core/concerns/liquid_renderable.rb b/bridgetown-core/lib/bridgetown-core/concerns/liquid_renderable.rb deleted file mode 100644 index 93fe6667d..000000000 --- a/bridgetown-core/lib/bridgetown-core/concerns/liquid_renderable.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Bridgetown - module LiquidRenderable - # Determine whether the file should be rendered with Liquid. - # - # Returns false if the document is a yaml file or if the document doesn't - # contain any Liquid Tags or Variables, true otherwise. - def render_with_liquid? - return false if data["render_with_liquid"] == false - return false unless liquid_engine_configured? - - !(yaml_file? || !Utils.has_liquid_construct?(content)) - end - - def liquid_engine_configured? - data["template_engine"].to_s == "liquid" || - ( - data["template_engine"].nil? && ( - site.config[:template_engine].nil? || site.config[:template_engine].to_s == "liquid" - ) - ) - end - - # Override in individual classes - def yaml_file? - false - end - end -end diff --git a/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb b/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb index 66ee9b08d..d2b6ecda1 100644 --- a/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb +++ b/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb @@ -33,12 +33,36 @@ def matched_converters_for_convertible(convertible) return @layout_converters[convertible] end - matches = converters.select do |converter| - if converter.method(:matches).arity == 1 - converter.matches(convertible.extname) - else - converter.matches(convertible.extname, convertible) + if convertible.is_a?(Bridgetown::GeneratedPage) && convertible.original_resource + convertible = convertible.original_resource + end + + directly_matched_template_engine = nil + matches = converters.map do |converter| + result = [ + converter, + converter.matches(convertible.extname, convertible), + converter.determine_template_engine(convertible), + ] + + directly_matched_template_engine = converter if result[1] && converter.class.template_engine + + result + end + + matches = matches.filter_map do |result| + converter, ext_matched, engine_matched = result + next nil if !ext_matched && !engine_matched + + next nil if !ext_matched && + engine_matched && directly_matched_template_engine && + converter != directly_matched_template_engine + + if !convertible.data["template_engine"] && engine_matched + convertible.data["template_engine"] = converter.class.template_engine end + + converter end @layout_converters[convertible] = matches if convertible.is_a?(Bridgetown::Layout) diff --git a/bridgetown-core/lib/bridgetown-core/configuration.rb b/bridgetown-core/lib/bridgetown-core/configuration.rb index 4288c9e07..03b369274 100644 --- a/bridgetown-core/lib/bridgetown-core/configuration.rb +++ b/bridgetown-core/lib/bridgetown-core/configuration.rb @@ -62,6 +62,7 @@ def initialize(*) "ruby_in_front_matter" => true, # Conversion + "template_engine" => "erb", "markdown" => "kramdown", "highlighter" => "rouge", diff --git a/bridgetown-core/lib/bridgetown-core/converter.rb b/bridgetown-core/lib/bridgetown-core/converter.rb index 84216f822..86c0d4876 100644 --- a/bridgetown-core/lib/bridgetown-core/converter.rb +++ b/bridgetown-core/lib/bridgetown-core/converter.rb @@ -15,13 +15,17 @@ def input(extnames) self.extname_list += extnames.map { |e| ".#{e.to_s.downcase}" } end - def supports_slots? - @support_slots == true - end + def supports_slots? = @support_slots - def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter + def support_slots(bool = nil) @support_slots = bool == true end + + def template_engine(name = nil) + return @template_engine unless name + + @template_engine = name.to_s + end end # Initialize the converter. @@ -48,24 +52,40 @@ def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgum # The file's extension (including the dot) # # @return [Boolean] Whether the extension matches one in the list - def matches(ext) + def matches(ext, convertible = nil) (self.class.extname_list || []).include?(ext.downcase) end - # You can override this in Converter subclasses as needed. Default is ".html" + def determine_template_engine(convertible) + template_engine = self.class.template_engine + convertible_engine = convertible.data["template_engine"].to_s + convertible_engine == template_engine || + (convertible_engine == "" && @config["template_engine"].to_s == template_engine) + end + + # You can override this in Converter subclasses as needed. Default is ".html", unless the + # converter is a template engine and the input file doesn't match the normal template extension # # @param [String] ext # The extension of the original file # # @return [String] The output file extension (including the dot) - def output_ext(_ext) - ".html" + def output_ext(ext) + if self.class.template_engine + (self.class.extname_list || []).include?(ext.downcase) ? ".html" : ext + else + ".html" + end end def line_start(convertible) if convertible.is_a?(Bridgetown::Resource::Base) && convertible.model.origin.respond_to?(:front_matter_line_count) - convertible.model.origin.front_matter_line_count + 4 + if convertible.model.origin.front_matter_line_count.nil? + 1 + else + convertible.model.origin.front_matter_line_count + 4 + end elsif convertible.is_a?(Bridgetown::GeneratedPage) && convertible.original_resource res = convertible.original_resource if res.model.origin.respond_to?(:front_matter_line_count) diff --git a/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb index 24eccd78d..59abab91f 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb @@ -106,6 +106,7 @@ module Converters class ERBTemplates < Converter priority :highest input :erb + template_engine :erb # Logic to do the ERB content conversion. # @@ -116,8 +117,6 @@ class ERBTemplates < Converter # # @return [String] The converted content. def convert(content, convertible) - return content if convertible.data[:template_engine].to_s != "erb" - erb_view = Bridgetown::ERBView.new(convertible) erb_renderer = Tilt::ErubiTemplate.new( @@ -136,25 +135,6 @@ def convert(content, convertible) erb_renderer.render(erb_view) end end - - # @param ext [String] - # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage] - def matches(ext, convertible) - if convertible.data[:template_engine].to_s == "erb" || - (convertible.data[:template_engine].nil? && - @config[:template_engine].to_s == "erb") - convertible.data[:template_engine] = "erb" - return true - end - - super(ext).tap do |ext_matches| - convertible.data[:template_engine] = "erb" if ext_matches - end - end - - def output_ext(ext) - ext == ".erb" ? ".html" : ext - end end end end diff --git a/bridgetown-core/lib/bridgetown-core/converters/identity.rb b/bridgetown-core/lib/bridgetown-core/converters/identity.rb index 544a5a167..261edba01 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/identity.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/identity.rb @@ -15,7 +15,7 @@ class Identity < Converter # _ext - The String extension to check (not relevant here) # # Returns true since it always matches. - def matches(_ext) + def matches(*) true end diff --git a/bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb index 265c3af39..b073821ff 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/liquid_templates.rb @@ -5,6 +5,7 @@ module Converters class LiquidTemplates < Converter priority :highest input :liquid + template_engine :liquid attr_reader :site, :document, :layout @@ -24,8 +25,6 @@ class << self # # @return [String] The converted content. def convert(content, convertible) - return content if convertible.data[:template_engine] != "liquid" - self.class.cached_partials ||= {} @payload = nil @@ -56,23 +55,6 @@ def convert(content, convertible) # rubocop: enable Metrics/MethodLength # rubocop: enable Metrics/AbcSize - # @param ext [String] - # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage] - def matches(ext, convertible) - if convertible.render_with_liquid? - convertible.data[:template_engine] = "liquid" - return true - end - - super(ext).tap do |ext_matches| - convertible.data[:template_engine] = "liquid" if ext_matches - end - end - - def output_ext(ext) - ext == ".liquid" ? ".html" : ext - end - # Fetches the payload used in Liquid rendering. # Falls back to site.site_payload if no payload is set. # diff --git a/bridgetown-core/lib/bridgetown-core/converters/ruby_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/ruby_templates.rb index 3744357ad..f66f540ad 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/ruby_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/ruby_templates.rb @@ -61,6 +61,7 @@ module Converters class RubyTemplates < Converter priority :highest input :rb + template_engine :ruby def convert(content, convertible) rb_view = Bridgetown::PureRubyView.new(convertible) diff --git a/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb index a19d0764b..c3ca3736a 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb @@ -22,6 +22,7 @@ def _render_partial(partial_name, options) module Converters class SerbeaTemplates < Converter priority :highest + template_engine :serbea input :serb # Logic to do the Serbea content conversion. @@ -33,8 +34,6 @@ class SerbeaTemplates < Converter # # @return [String] The converted content. def convert(content, convertible) - return content if convertible.data[:template_engine].to_s != "serbea" - serb_view = Bridgetown::SerbeaView.new(convertible) serb_renderer = Tilt::SerbeaTemplate.new( convertible.path, @@ -49,23 +48,6 @@ def convert(content, convertible) serb_renderer.render(serb_view) end end - - def matches(ext, convertible) - if convertible.data[:template_engine].to_s == "serbea" || - (convertible.data[:template_engine].nil? && - @config[:template_engine].to_s == "serbea") - convertible.data[:template_engine] = "serbea" - return true - end - - super(ext).tap do |ext_matches| - convertible.data[:template_engine] = "serbea" if ext_matches - end - end - - def output_ext(ext) - ext == ".serb" ? ".html" : ext - end end end end diff --git a/bridgetown-core/lib/bridgetown-core/generated_page.rb b/bridgetown-core/lib/bridgetown-core/generated_page.rb index 18030543e..53430af4c 100644 --- a/bridgetown-core/lib/bridgetown-core/generated_page.rb +++ b/bridgetown-core/lib/bridgetown-core/generated_page.rb @@ -3,7 +3,6 @@ module Bridgetown class GeneratedPage include LayoutPlaceable - include LiquidRenderable include Localizable include Publishable include Transformable diff --git a/bridgetown-core/lib/bridgetown-core/layout.rb b/bridgetown-core/lib/bridgetown-core/layout.rb index cbf1a4882..587a75e07 100644 --- a/bridgetown-core/lib/bridgetown-core/layout.rb +++ b/bridgetown-core/lib/bridgetown-core/layout.rb @@ -3,7 +3,6 @@ module Bridgetown class Layout include FrontMatter::Importer - include LiquidRenderable # Gets the Site object. attr_reader :site diff --git a/bridgetown-core/lib/bridgetown-core/resource/base.rb b/bridgetown-core/lib/bridgetown-core/resource/base.rb index 5344aa285..4157e4b06 100644 --- a/bridgetown-core/lib/bridgetown-core/resource/base.rb +++ b/bridgetown-core/lib/bridgetown-core/resource/base.rb @@ -6,7 +6,6 @@ class Base # rubocop:todo Metrics/ClassLength include Comparable include Bridgetown::Publishable include Bridgetown::LayoutPlaceable - include Bridgetown::LiquidRenderable include Bridgetown::Localizable # @return [Destination] diff --git a/bridgetown-core/lib/bridgetown-core/utils.rb b/bridgetown-core/lib/bridgetown-core/utils.rb index 22dde6e64..b8aff047b 100644 --- a/bridgetown-core/lib/bridgetown-core/utils.rb +++ b/bridgetown-core/lib/bridgetown-core/utils.rb @@ -139,16 +139,6 @@ def has_rbfm_header?(file) FrontMatter::Loaders::Ruby.header?(file) end - # Determine whether the given content string contains Liquid Tags or Vaiables - # - # @return [Boolean] if the string contains sequences of `{%` or `{{` - def has_liquid_construct?(content) - return false if content.nil? || content.empty? - - content.include?("{%") || content.include?("{{") - end - # rubocop: enable Naming/PredicateName - # Slugify a filename or title. # # string - the filename or title to slugify From 94f6b6171c9721941ea3ad6dc95d6fd1ddb4a086 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sun, 28 Apr 2024 07:42:35 -0700 Subject: [PATCH 4/5] First round of updated tests --- .../test/features/test_collections_dir.rb | 4 +- bridgetown-core/test/features/test_data.rb | 8 ++-- .../test/features/test_liquid_rendering.rb | 4 +- .../test/features/test_pagination.rb | 6 +-- .../src/_events/2020-12-25-christmas.html | 1 - ...multi-page-with-specified-locales.multi.md | 1 + .../resources/src/_pages/multi-page.multi.md | 1 + .../src/_pages/second-level-page.en.md | 2 +- .../src/_pages/second-level-page.fr.md | 2 +- .../test/resources/src/top-level-page.md | 1 + .../test/source/src/_layouts/default.html | 1 + .../_thanksgiving/2015-11-26-thanksgiving.md | 1 + .../source/src/_thanksgiving/black-friday.md | 1 + .../test/source/src/environment.html | 1 + bridgetown-core/test/source/src/index.html | 1 + bridgetown-core/test/test_filters.rb | 41 ++++++++++--------- bridgetown-core/test/test_resource.rb | 4 -- 17 files changed, 43 insertions(+), 37 deletions(-) diff --git a/bridgetown-core/test/features/test_collections_dir.rb b/bridgetown-core/test/features/test_collections_dir.rb index 344de7161..d74c83748 100644 --- a/bridgetown-core/test/features/test_collections_dir.rb +++ b/bridgetown-core/test/features/test_collections_dir.rb @@ -97,6 +97,7 @@ class TestCollectionsDir < BridgetownFeatureTest create_page "gathering/_players/standby/loki.md", "content for Loki.", title: "Loki" create_file "bridgetown.config.yml", <<~YAML + template_engine: liquid collections_dir: gathering collections: ["players"] defaults: @@ -160,7 +161,7 @@ class TestCollectionsDir < BridgetownFeatureTest create_directory "gathering" setup_collections_fixture "gathering" - create_page "index.html", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Simple Test" + create_page "index.liquid", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Simple Test" create_directory "_layouts" create_file "_layouts/tutorial.html", <<~LIQUID @@ -207,6 +208,7 @@ class TestCollectionsDir < BridgetownFeatureTest LIQUID create_file "bridgetown.config.yml", <<~YAML + template_engine: liquid collections_dir: gathering collections: tutorials: diff --git a/bridgetown-core/test/features/test_data.rb b/bridgetown-core/test/features/test_data.rb index 110a73b1f..89bc1216b 100644 --- a/bridgetown-core/test/features/test_data.rb +++ b/bridgetown-core/test/features/test_data.rb @@ -46,7 +46,7 @@ class TestData < BridgetownFeatureTest [{"name": "Jack", "age": 28},{"name": "Leon", "age": 34}] JSON - create_page "index.html", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" @@ -61,7 +61,7 @@ class TestData < BridgetownFeatureTest Leon,34 CSV - create_page "index.html", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" @@ -92,7 +92,7 @@ class TestData < BridgetownFeatureTest age: 34 YAML - create_page "index.html", "{% for member in site.data.team_members %}{{member.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for member in site.data.team_members %}{{member.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" @@ -112,7 +112,7 @@ class TestData < BridgetownFeatureTest name: Produce Products YAML - create_page "index.html", "{{ site.data.categories.dairy.name }} {{ site.data.categories.produce.name }}", title: "Simple Test" + create_page "index.liquid", "{{ site.data.categories.dairy.name }} {{ site.data.categories.produce.name }}", title: "Simple Test" run_bridgetown "build" diff --git a/bridgetown-core/test/features/test_liquid_rendering.rb b/bridgetown-core/test/features/test_liquid_rendering.rb index d9a098980..46512484e 100644 --- a/bridgetown-core/test/features/test_liquid_rendering.rb +++ b/bridgetown-core/test/features/test_liquid_rendering.rb @@ -102,8 +102,8 @@ class TestLiquidRendering < BridgetownFeatureTest end should "not process Liquid when render_with_liquid: false" do - create_page "_posts/unrendered-post.md", "Hello {{ page.title }}", date: "2017-07-06", render_with_liquid: false - create_page "_posts/rendered-post.md", "Hello {{ page.title }}", date: "2017-07-06", render_with_liquid: true + create_page "_posts/unrendered-post.md", "Hello {{ page.title }}", date: "2017-07-06" + create_page "_posts/rendered-post.md", "Hello {{ page.title }}", date: "2017-07-06", template_engine: "liquid" run_bridgetown "build" diff --git a/bridgetown-core/test/features/test_pagination.rb b/bridgetown-core/test/features/test_pagination.rb index de30e78b2..3e0fb1e70 100644 --- a/bridgetown-core/test/features/test_pagination.rb +++ b/bridgetown-core/test/features/test_pagination.rb @@ -24,7 +24,7 @@ class TestPagination < BridgetownFeatureTest should "paginate with #{example[:num]} posts per page" do create_configuration pagination: { enabled: true, per_page: example[:num] } - create_page "index.html", "{{ paginator.resources.size }} {{ paginator.resources[0].title }}", pagination: { collection: "posts" } + create_page "index.liquid", "{{ paginator.resources.size }} {{ paginator.resources[0].title }}", pagination: { collection: "posts" } run_bridgetown "build" @@ -45,7 +45,7 @@ class TestPagination < BridgetownFeatureTest permalink: "/blog/:year/:month/:day/:title" create_directory "blog" - create_page "blog/index.html", "{{ paginator.resources.size }}", pagination: { collection: "posts" } + create_page "blog/index.liquid", "{{ paginator.resources.size }}", pagination: { collection: "posts" } run_bridgetown "build" @@ -74,7 +74,7 @@ class TestPagination < BridgetownFeatureTest should "paginate #{example[:num]} posts per page with tags" do create_configuration pagination: { enabled: true, per_page: example[:num] } - create_page "index.html", "{{ paginator.resources.size }} {{ paginator.resources[0].title }}", pagination: { collection: "posts", tag: "scary" } + create_page "index.liquid", "{{ paginator.resources.size }} {{ paginator.resources[0].title }}", pagination: { collection: "posts", tag: "scary" } run_bridgetown "build" diff --git a/bridgetown-core/test/resources/src/_events/2020-12-25-christmas.html b/bridgetown-core/test/resources/src/_events/2020-12-25-christmas.html index da8e5abfc..beeca9df1 100644 --- a/bridgetown-core/test/resources/src/_events/2020-12-25-christmas.html +++ b/bridgetown-core/test/resources/src/_events/2020-12-25-christmas.html @@ -2,7 +2,6 @@ front_matter do old_title "Christmas 2019" title old_title.sub("2019", "2020") - template_engine :erb end %>--- diff --git a/bridgetown-core/test/resources/src/_pages/multi-page-with-specified-locales.multi.md b/bridgetown-core/test/resources/src/_pages/multi-page-with-specified-locales.multi.md index 0d5c7dfe4..aef0cf548 100644 --- a/bridgetown-core/test/resources/src/_pages/multi-page-with-specified-locales.multi.md +++ b/bridgetown-core/test/resources/src/_pages/multi-page-with-specified-locales.multi.md @@ -1,6 +1,7 @@ --- layout: localization title: "Multi-locale with specified locales page" +template_engine: liquid locales: - en --- diff --git a/bridgetown-core/test/resources/src/_pages/multi-page.multi.md b/bridgetown-core/test/resources/src/_pages/multi-page.multi.md index 2ced24d8f..3909dfbc1 100644 --- a/bridgetown-core/test/resources/src/_pages/multi-page.multi.md +++ b/bridgetown-core/test/resources/src/_pages/multi-page.multi.md @@ -1,6 +1,7 @@ --- layout: localization title: "Multi-locale page" +template_engine: liquid locale_overrides: fr: title: "Sur mesure" diff --git a/bridgetown-core/test/resources/src/_pages/second-level-page.en.md b/bridgetown-core/test/resources/src/_pages/second-level-page.en.md index 0d95ecc70..e94303e50 100644 --- a/bridgetown-core/test/resources/src/_pages/second-level-page.en.md +++ b/bridgetown-core/test/resources/src/_pages/second-level-page.en.md @@ -1,5 +1,5 @@ ~~~ruby -{ title: "I'm a Second Level Page" } +{ title: "I'm a Second Level Page", template_engine: :liquid } ~~~ That's **nice**. diff --git a/bridgetown-core/test/resources/src/_pages/second-level-page.fr.md b/bridgetown-core/test/resources/src/_pages/second-level-page.fr.md index f6f4ae319..339848347 100644 --- a/bridgetown-core/test/resources/src/_pages/second-level-page.fr.md +++ b/bridgetown-core/test/resources/src/_pages/second-level-page.fr.md @@ -1,5 +1,5 @@ ~~~ruby -{ title: "I'm a Second Level Page in French" } +{ title: "I'm a Second Level Page in French", template_engine: :liquid } ~~~ C'est **bien**. diff --git a/bridgetown-core/test/resources/src/top-level-page.md b/bridgetown-core/test/resources/src/top-level-page.md index 1fa967b92..fcf83a424 100644 --- a/bridgetown-core/test/resources/src/top-level-page.md +++ b/bridgetown-core/test/resources/src/top-level-page.md @@ -1,6 +1,7 @@ --- layout: default title: I'm a Top Level Page! +template_engine: liquid --- That's **great**! diff --git a/bridgetown-core/test/source/src/_layouts/default.html b/bridgetown-core/test/source/src/_layouts/default.html index ef2d4384b..627ad1a43 100644 --- a/bridgetown-core/test/source/src/_layouts/default.html +++ b/bridgetown-core/test/source/src/_layouts/default.html @@ -1,5 +1,6 @@ --- front_matter_var: variable from layout +template_engine: liquid --- diff --git a/bridgetown-core/test/source/src/_thanksgiving/2015-11-26-thanksgiving.md b/bridgetown-core/test/source/src/_thanksgiving/2015-11-26-thanksgiving.md index 48d2dd58c..dd4ef0f2e 100644 --- a/bridgetown-core/test/source/src/_thanksgiving/2015-11-26-thanksgiving.md +++ b/bridgetown-core/test/source/src/_thanksgiving/2015-11-26-thanksgiving.md @@ -1,3 +1,4 @@ --- +template_engine: liquid --- Happy {{ page.title }} ! diff --git a/bridgetown-core/test/source/src/_thanksgiving/black-friday.md b/bridgetown-core/test/source/src/_thanksgiving/black-friday.md index 1d8ea1bba..a9c5db1e2 100644 --- a/bridgetown-core/test/source/src/_thanksgiving/black-friday.md +++ b/bridgetown-core/test/source/src/_thanksgiving/black-friday.md @@ -1,3 +1,4 @@ --- +template_engine: liquid --- {{ page.title }} diff --git a/bridgetown-core/test/source/src/environment.html b/bridgetown-core/test/source/src/environment.html index 4f0c43910..9e9119a05 100644 --- a/bridgetown-core/test/source/src/environment.html +++ b/bridgetown-core/test/source/src/environment.html @@ -1,5 +1,6 @@ --- title: I'm a Bridgetown environment exchequer +template_engine: liquid --- {{ bridgetown.environment }} diff --git a/bridgetown-core/test/source/src/index.html b/bridgetown-core/test/source/src/index.html index ffc668114..842111cc4 100644 --- a/bridgetown-core/test/source/src/index.html +++ b/bridgetown-core/test/source/src/index.html @@ -1,5 +1,6 @@ --- layout: default +template_engine: liquid title: Tom Preston-Werner --- diff --git a/bridgetown-core/test/test_filters.rb b/bridgetown-core/test/test_filters.rb index 055e8e134..a2097a6b3 100644 --- a/bridgetown-core/test/test_filters.rb +++ b/bridgetown-core/test/test_filters.rb @@ -856,10 +856,10 @@ def to_liquid should "convert drop to json" do @filter.site.read expected = { - "output" => nil, - "id" => "repo://posts.collection/_posts/2008-02-02-published.markdown", - "relative_url" => "/base/publish_test/2008/02/02/published/", - "taxonomies" => { + "output" => nil, + "id" => "repo://posts.collection/_posts/2008-02-02-published.markdown", + "relative_url" => "/base/publish_test/2008/02/02/published/", + "taxonomies" => { "category" => { "type" => { "label" => "category", @@ -883,11 +883,11 @@ def to_liquid "terms" => [], }, }, - "relative_path" => "_posts/2008-02-02-published.markdown", - "next" => nil, - "date" => "2008-02-02 00:00:00 +0000", - "summary" => "This should be published.", - "data" => { + "relative_path" => "_posts/2008-02-02-published.markdown", + "next" => nil, + "date" => "2008-02-02 00:00:00 +0000", + "summary" => "This should be published.", + "data" => { "ruby3" => "groovy", "layout" => "default", "title" => "Publish", @@ -900,17 +900,18 @@ def to_liquid "date" => "2008-02-02 00:00:00 +0000", "slug" => "published", }, - "absolute_url" => "http://example.com/base/publish_test/2008/02/02/published/", - "collection" => "posts", - "content" => "This should be published.\n", - "ruby3" => "groovy", - "layout" => "default", - "title" => "Publish", - "category" => "publish_test", - "categories" => ["publish_test"], - "tags" => [], - "locale" => "en", - "slug" => "published", + "absolute_url" => "http://example.com/base/publish_test/2008/02/02/published/", + "collection" => "posts", + "content" => "This should be published.\n", + "ruby3" => "groovy", + "layout" => "default", + "title" => "Publish", + "category" => "publish_test", + "categories" => ["publish_test"], + "tags" => [], + "locale" => "en", + "slug" => "published", + "template_engine" => "erb", } actual = JSON.parse(@filter.jsonify(@filter.site.resources_to_write.find do |post| post.data.title == "Publish" && post.data.slug == "published" diff --git a/bridgetown-core/test/test_resource.rb b/bridgetown-core/test/test_resource.rb index 82e8fcc9c..620c537d2 100644 --- a/bridgetown-core/test/test_resource.rb +++ b/bridgetown-core/test/test_resource.rb @@ -39,10 +39,6 @@ class TestResource < BridgetownUnitTest assert_equal "default", @resource.layout.label end - should "know whether it's a YAML file" do - assert_equal false, @resource.yaml_file? - end - should "know its data" do assert_equal "I'm a Top Level Page!", @resource.data.title end From 717e5631952bfc96e5856dd818d660e34850c403 Mon Sep 17 00:00:00 2001 From: Jared White Date: Sun, 28 Apr 2024 10:56:44 -0700 Subject: [PATCH 5/5] Many bug fixes, all tests passing --- .../concerns/site/renderable.rb | 2 +- .../lib/bridgetown-core/configuration.rb | 12 +++++++----- .../lib/bridgetown-core/converter.rb | 7 ++++--- bridgetown-core/lib/bridgetown-core/slot.rb | 2 +- bridgetown-core/lib/bridgetown-core/utils.rb | 5 ++--- .../test/features/test_asset_path_tag.rb | 10 +++++----- bridgetown-core/test/features/test_cache.rb | 6 +++--- .../features/test_collection_rendering.rb | 4 ++-- .../test/features/test_collections_dir.rb | 6 +++--- bridgetown-core/test/features/test_data.rb | 6 +++--- bridgetown-core/test/features/test_hooks.rb | 12 ++++++------ .../test/features/test_liquid_rendering.rb | 10 +++++----- .../test/features/test_permalinks.rb | 4 ++-- .../test/features/test_ruby_rendering.rb | 13 +++++-------- .../test/features/test_site_configuration.rb | 6 +++--- .../layouts/example/overridden_layout.html | 2 +- .../layouts/example/test_layout.html | 2 +- bridgetown-core/test/source/_config.dev.toml | 2 -- ...n_layout.html => overridden_layout.liquid} | 0 .../test/source/src/_methods/configuration.md | 1 + .../{components.html => components.liquid} | 0 .../source/src/plugin_content/layouts.html | 8 -------- .../source/src/plugin_content/layouts.serb | 8 ++++++++ bridgetown-core/test/test_configuration.rb | 12 +----------- bridgetown-core/test/test_filters.rb | 19 ++++++++++--------- bridgetown-core/test/test_generated_page.rb | 1 + bridgetown-core/test/test_new_command.rb | 2 +- bridgetown-core/test/test_site.rb | 4 ++-- 28 files changed, 78 insertions(+), 88 deletions(-) delete mode 100644 bridgetown-core/test/source/_config.dev.toml rename bridgetown-core/test/source/src/_layouts/example/{overridden_layout.html => overridden_layout.liquid} (100%) rename bridgetown-core/test/source/src/plugin_content/{components.html => components.liquid} (100%) delete mode 100644 bridgetown-core/test/source/src/plugin_content/layouts.html create mode 100644 bridgetown-core/test/source/src/plugin_content/layouts.serb diff --git a/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb b/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb index d2b6ecda1..d6b67e61c 100644 --- a/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb +++ b/bridgetown-core/lib/bridgetown-core/concerns/site/renderable.rb @@ -26,7 +26,7 @@ def execute_inline_ruby_for_layouts! end end - def matched_converters_for_convertible(convertible) + def matched_converters_for_convertible(convertible) # rubocop:todo Metrics @layout_converters ||= {} if convertible.is_a?(Bridgetown::Layout) && @layout_converters[convertible] diff --git a/bridgetown-core/lib/bridgetown-core/configuration.rb b/bridgetown-core/lib/bridgetown-core/configuration.rb index 03b369274..beb2cfc4d 100644 --- a/bridgetown-core/lib/bridgetown-core/configuration.rb +++ b/bridgetown-core/lib/bridgetown-core/configuration.rb @@ -222,10 +222,7 @@ def config_files(override) # By default only the first matching config file will be loaded, but # multiple configs can be specified via command line. config_files = override["config"] - if config_files.to_s.empty? - config_files = "bridgetown.config.yml" - @default_config_file = true - end + config_files = "bridgetown.config.yml" if config_files.to_s.empty? Array(config_files) end @@ -260,8 +257,10 @@ def read_config_files(files) # # @return [Hash] def read_config_file(file) + default_config_file = file == "bridgetown.config.yml" file = File.expand_path(file) - return {} unless File.exist?(file) + # We don't care if default config is missing, we can return blank: + return {} if !File.exist?(file) && default_config_file file_config = safe_load_file(file) @@ -271,6 +270,9 @@ def read_config_file(file) Bridgetown.logger.debug "Configuration file:", file file_config + rescue SystemCallError + Bridgetown.logger.error "Fatal:", "The configuration file '#{file}' could not be found." + raise LoadError, "missing configuration file" end # Merge in environment-specific options, if present diff --git a/bridgetown-core/lib/bridgetown-core/converter.rb b/bridgetown-core/lib/bridgetown-core/converter.rb index 86c0d4876..d5c07b44f 100644 --- a/bridgetown-core/lib/bridgetown-core/converter.rb +++ b/bridgetown-core/lib/bridgetown-core/converter.rb @@ -17,7 +17,7 @@ def input(extnames) def supports_slots? = @support_slots - def support_slots(bool = nil) + def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter @support_slots = bool == true end @@ -50,9 +50,10 @@ def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgum # # @param [String] ext # The file's extension (including the dot) + # @param convertible [Bridgetown::Layout, Bridgetown::Resource::Base] # # @return [Boolean] Whether the extension matches one in the list - def matches(ext, convertible = nil) + def matches(ext, _convertible = nil) (self.class.extname_list || []).include?(ext.downcase) end @@ -78,7 +79,7 @@ def output_ext(ext) end end - def line_start(convertible) + def line_start(convertible) # rubocop:disable Metrics/PerceivedComplexity if convertible.is_a?(Bridgetown::Resource::Base) && convertible.model.origin.respond_to?(:front_matter_line_count) if convertible.model.origin.front_matter_line_count.nil? diff --git a/bridgetown-core/lib/bridgetown-core/slot.rb b/bridgetown-core/lib/bridgetown-core/slot.rb index 53895d9dd..8eb761a97 100644 --- a/bridgetown-core/lib/bridgetown-core/slot.rb +++ b/bridgetown-core/lib/bridgetown-core/slot.rb @@ -28,7 +28,7 @@ def transform! private def converters - # A private method calling another private method. Hmm. + # TODO: a private method calling another private method. Hmm. document_converters = context.is_a?(Bridgetown::Resource::Base) ? context.transformer.send(:converters) : context.send(:converters) diff --git a/bridgetown-core/lib/bridgetown-core/utils.rb b/bridgetown-core/lib/bridgetown-core/utils.rb index b8aff047b..04fff0aeb 100644 --- a/bridgetown-core/lib/bridgetown-core/utils.rb +++ b/bridgetown-core/lib/bridgetown-core/utils.rb @@ -122,8 +122,7 @@ def parse_date(input, msg = "Input could not be parsed.") # Determines whether a given file has # # @return [Boolean] if the YAML front matter is present. - # rubocop: disable Naming/PredicateName - def has_yaml_header?(file) + def has_yaml_header?(file) # rubocop: disable Naming/PredicateName Bridgetown::Deprecator.deprecation_message( "Bridgetown::Utils.has_yaml_header? is deprecated, use " \ "Bridgetown::FrontMatter::Loaders::YAML.header? instead" @@ -131,7 +130,7 @@ def has_yaml_header?(file) FrontMatter::Loaders::YAML.header?(file) end - def has_rbfm_header?(file) + def has_rbfm_header?(file) # rubocop: disable Naming/PredicateName Bridgetown::Deprecator.deprecation_message( "Bridgetown::Utils.has_rbfm_header? is deprecated, use " \ "Bridgetown::FrontMatter::Loaders::Ruby.header? instead" diff --git a/bridgetown-core/test/features/test_asset_path_tag.rb b/bridgetown-core/test/features/test_asset_path_tag.rb index 3197287a0..05abeb9ae 100644 --- a/bridgetown-core/test/features/test_asset_path_tag.rb +++ b/bridgetown-core/test/features/test_asset_path_tag.rb @@ -8,13 +8,13 @@ class TestAssetPathTag < BridgetownFeatureTest context "frontend manifest" do setup do create_directory "_layouts" - create_page "index.html", "page content", layout: "default" + create_page "index.liquid", "page content", layout: "default" create_file "esbuild.config.js", "" create_directory ".bridgetown-cache/frontend-bundling" end should "load for asset_tag" do - create_file "_layouts/default.html", <<~HTML + create_file "_layouts/default.liquid", <<~HTML @@ -43,7 +43,7 @@ class TestAssetPathTag < BridgetownFeatureTest end should "provide custom files" do - create_file "_layouts/default.html", <<~HTML + create_file "_layouts/default.liquid", <<~HTML @@ -69,7 +69,7 @@ class TestAssetPathTag < BridgetownFeatureTest end should "report when missing" do - create_file "_layouts/default.html", <<~HTML + create_file "_layouts/default.liquid", <<~HTML @@ -88,7 +88,7 @@ class TestAssetPathTag < BridgetownFeatureTest end should "handle missing asset files" do - create_file "_layouts/default.html", <<~HTML + create_file "_layouts/default.liquid", <<~HTML diff --git a/bridgetown-core/test/features/test_cache.rb b/bridgetown-core/test/features/test_cache.rb index da0b1f698..618657346 100644 --- a/bridgetown-core/test/features/test_cache.rb +++ b/bridgetown-core/test/features/test_cache.rb @@ -7,7 +7,7 @@ class TestCache < BridgetownFeatureTest context "cache folder" do should "exist after build" do - create_page "index.md", "{{ data.title }}", title: "Hello World" + create_page "index.md", "<%= data.title %>", title: "Hello World" run_bridgetown "build" @@ -17,7 +17,7 @@ class TestCache < BridgetownFeatureTest end should "support custom cache configuration" do - create_page "index.md", "{{ data.title }}", title: "Hello World" + create_page "index.md", "<%= data.title %>", title: "Hello World" create_configuration cache_dir: ".foo-cache" run_bridgetown "build" @@ -29,7 +29,7 @@ class TestCache < BridgetownFeatureTest end should "not exist after build with CLI flag" do - create_page "index.md", "{{ data.title }}", title: "Hello World" + create_page "index.md", "<%= data.title %>", title: "Hello World" run_bridgetown "build", "--disable-disk-cache" diff --git a/bridgetown-core/test/features/test_collection_rendering.rb b/bridgetown-core/test/features/test_collection_rendering.rb index 81aa56795..13f52b14a 100644 --- a/bridgetown-core/test/features/test_collection_rendering.rb +++ b/bridgetown-core/test/features/test_collection_rendering.rb @@ -79,7 +79,7 @@ class TestCollectionRendering < BridgetownFeatureTest should "sort based on configured front matter key" do create_page "index.liquid", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Index" - create_file "_layouts/tutorial.html", <<~LIQUID + create_file "_layouts/tutorial.liquid", <<~LIQUID {% if page.previous %}Previous: {{ page.previous.title }}{% endif %} {% if page.next %}Next: {{ page.next.title }}{% endif %} @@ -99,7 +99,7 @@ class TestCollectionRendering < BridgetownFeatureTest should "sort even when front matter key is sometimes missing" do create_page "index.liquid", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Index" - create_file "_layouts/tutorial.html", <<~LIQUID + create_file "_layouts/tutorial.liquid", <<~LIQUID {% if page.previous %}Previous: {{ page.previous.title }}{% endif %} {% if page.next %}Next: {{ page.next.title }}{% endif %} diff --git a/bridgetown-core/test/features/test_collections_dir.rb b/bridgetown-core/test/features/test_collections_dir.rb index d74c83748..f91747287 100644 --- a/bridgetown-core/test/features/test_collections_dir.rb +++ b/bridgetown-core/test/features/test_collections_dir.rb @@ -164,7 +164,7 @@ class TestCollectionsDir < BridgetownFeatureTest create_page "index.liquid", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Simple Test" create_directory "_layouts" - create_file "_layouts/tutorial.html", <<~LIQUID + create_file "_layouts/tutorial.liquid", <<~LIQUID {% if page.previous %}Previous: {{ page.previous.title }}{% endif %} {% if page.next %}Next: {{ page.next.title }}{% endif %} @@ -198,10 +198,10 @@ class TestCollectionsDir < BridgetownFeatureTest create_directory "gathering" setup_collections_fixture "gathering" - create_page "index.html", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Simple Test" + create_page "index.liquid", "Collections: {{ collections.tutorials.resources | map: 'title' | join: ', ' }}", title: "Simple Test" create_directory "_layouts" - create_file "_layouts/tutorial.html", <<~LIQUID + create_file "_layouts/tutorial.liquid", <<~LIQUID {% if page.previous %}Previous: {{ page.previous.title }}{% endif %} {% if page.next %}Next: {{ page.next.title }}{% endif %} diff --git a/bridgetown-core/test/features/test_data.rb b/bridgetown-core/test/features/test_data.rb index 89bc1216b..42ee2cc3b 100644 --- a/bridgetown-core/test/features/test_data.rb +++ b/bridgetown-core/test/features/test_data.rb @@ -17,7 +17,7 @@ class TestData < BridgetownFeatureTest price: 2.5 YAML - create_page "index.html", "{% for product in site.data.products %}{{product.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for product in site.data.products %}{{product.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" @@ -33,7 +33,7 @@ class TestData < BridgetownFeatureTest age: 34 YAML - create_page "index.html", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" @@ -76,7 +76,7 @@ class TestData < BridgetownFeatureTest Gertrude 34 TSV - create_page "index.html", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" + create_page "index.liquid", "{% for member in site.data.members %}{{member.name}}{% endfor %}", title: "Simple Test" run_bridgetown "build" diff --git a/bridgetown-core/test/features/test_hooks.rb b/bridgetown-core/test/features/test_hooks.rb index fb4705e6f..adc6c301e 100644 --- a/bridgetown-core/test/features/test_hooks.rb +++ b/bridgetown-core/test/features/test_hooks.rb @@ -108,7 +108,7 @@ module Ext RUBY create_directory "_posts" - create_page "_posts/entry1.md", "{{ page.harold }}", title: "entry1", date: "2015-03-14" + create_page "_posts/entry1.md", "{{ page.harold }}", title: "entry1", date: "2015-03-14", template_engine: "liquid" run_bridgetown "build" @@ -129,8 +129,8 @@ module Ext RUBY create_directory "_posts" - create_page "_posts/entry1.md", "{{ page.myvar }} post", title: "entry1", date: "2015-03-14" - create_page "_posts/entry2.md", "{{ page.myvar }} post", title: "entry2", date: "2015-03-15" + create_page "_posts/entry1.md", "{{ page.myvar }} post", title: "entry1", date: "2015-03-14", template_engine: "liquid" + create_page "_posts/entry2.md", "{{ page.myvar }} post", title: "entry2", date: "2015-03-15", template_engine: "liquid" run_bridgetown "build" @@ -148,8 +148,8 @@ module Ext RUBY create_directory "_posts" - create_page "_posts/entry1.md", "{{ 6 | times: 7 }}", title: "entry1", date: "2015-03-14" - create_page "_posts/entry2.md", "{{ 6 | times: 8 }}", title: "entry2", date: "2015-03-15" + create_page "_posts/entry1.md", "{{ 6 | *: 7 }}", title: "entry1", date: "2015-03-14", template_engine: "serbea" + create_page "_posts/entry2.md", "{{ 6 | *: 8 }}", title: "entry2", date: "2015-03-15", template_engine: "serbea" run_bridgetown "build" @@ -240,7 +240,7 @@ module Ext create_directory "_memes" create_page "_memes/doc1.md", "", text: "all your base" - create_page "index.md", "{{ collections.memes.resources.first.text }}", title: "Simple test" + create_page "index.md", "{{ collections.memes.resources.first.text }}", title: "Simple test", template_engine: "liquid" create_configuration collections: ["memes"] diff --git a/bridgetown-core/test/features/test_liquid_rendering.rb b/bridgetown-core/test/features/test_liquid_rendering.rb index 46512484e..dc89e58c6 100644 --- a/bridgetown-core/test/features/test_liquid_rendering.rb +++ b/bridgetown-core/test/features/test_liquid_rendering.rb @@ -6,7 +6,7 @@ class TestLiquidRendering < BridgetownFeatureTest context "Liquid templates" do should "pull resource data into layout" do - create_page "index.html", "", layout: "simple", author: "John Doe" + create_page "index.html", "", layout: "simple", author: "John Doe", template_engine: "liquid" create_directory "_layouts" create_file "_layouts/simple.liquid", "{{ page.author }}:{{ resource.author }}:{{ resource.data.author }}" @@ -233,12 +233,12 @@ class TestLiquidRendering < BridgetownFeatureTest context "overridden defaults and placed layouts" do should "ensure layout set to none doesn't render any layout" do - create_page "index.md", "Hi there, {{ site.author }}!", layout: "none" + create_page "index.md", "Hi there, <%= site.config.author %>!", layout: "none" create_directory "_trials" - create_page "_trials/no-layout.md", "Hi there, {{ site.author }}!", layout: "none" - create_page "_trials/false-layout.md", "Hi there, {{ site.author }}!", layout: false - create_page "test.md", "Hi there, {{ site.author }}!", layout: "page" + create_page "_trials/no-layout.md", "Hi there, <%= site.config.author %>!", layout: "none" + create_page "_trials/false-layout.md", "Hi there, <%= site.config.author %>!", layout: false + create_page "test.md", "Hi there, <%= site.config.author %>!", layout: "page" create_directory "_layouts" create_file "_layouts/none.liquid", "{{ content }}Welcome!" diff --git a/bridgetown-core/test/features/test_permalinks.rb b/bridgetown-core/test/features/test_permalinks.rb index bb65ad937..e98d82dc7 100644 --- a/bridgetown-core/test/features/test_permalinks.rb +++ b/bridgetown-core/test/features/test_permalinks.rb @@ -110,8 +110,8 @@ class TestPermalinks < BridgetownFeatureTest should "support multi-lingual rendering within custom collections" do create_directory "_blogs" - create_page "_blogs/2024-02-27-multi-lingual.md", "Awesome! {{ site.locale }}", title: "English Locale" - create_page "_blogs/2024-02-27-multi-lingual.es.md", "Impresionante! {{ site.locale }}", title: "Custom Locale" + create_page "_blogs/2024-02-27-multi-lingual.md", "Awesome! {{ site.locale }}", title: "English Locale", template_engine: "liquid" + create_page "_blogs/2024-02-27-multi-lingual.es.md", "Impresionante! {{ site.locale }}", title: "Custom Locale", template_engine: "liquid" create_configuration collections: { blogs: { output: true, permalink: "/:locale/:collection/:slug/" } }, available_locales: %w[en es] run_bridgetown "build" diff --git a/bridgetown-core/test/features/test_ruby_rendering.rb b/bridgetown-core/test/features/test_ruby_rendering.rb index aa95eeb30..a92ef214b 100644 --- a/bridgetown-core/test/features/test_ruby_rendering.rb +++ b/bridgetown-core/test/features/test_ruby_rendering.rb @@ -17,8 +17,6 @@ class TestRubyRendering < BridgetownFeatureTest create_file "_layouts/simple.html", "

<%= page.data.title %>

<%= yield %>" - create_configuration template_engine: "erb" - run_bridgetown "build" assert_file_contains "

Luke, I am your father.

", "output/2009/03/27/star-wars/index.html" @@ -32,8 +30,6 @@ class TestRubyRendering < BridgetownFeatureTest create_file "_layouts/simple.liquid", "

{{ page.title }}

{{ content }}" - create_configuration template_engine: "erb" - run_bridgetown "build" assert_file_contains "

Luke, I am your father.

", "output/2009/03/27/star-wars/index.html" @@ -80,7 +76,7 @@ class TestRubyRendering < BridgetownFeatureTest _Luke_, <%= ["I", "am"].join(" ") %> your father. ERB - create_file "_layouts/simple.html", <<~LIQUID + create_file "_layouts/simple.liquid", <<~LIQUID

{{ page.title }}

{{ content }} LIQUID @@ -180,11 +176,12 @@ class TestRubyRendering < BridgetownFeatureTest should "replace slot" do create_page "_posts/star-wars.md", <<~ERB, title: "Star Wars", date: "2009-03-27", layout: "simple" <% slot "title" do %># Star Trek<% end %><% slot "title", replace: true do %> # <%= data.title %><% end %> - ERB - create_file "_layouts/simple.html", '<%= slotted :title, "[BLANK]" %> <%= yield %>' + # Foo Bar + Hello **world** + ERB - create_configuration template_engine: "erb" + create_file "_layouts/simple.html", '<%= slotted :title, "[BLANK]" %> <%= yield %> The END' run_bridgetown "build" diff --git a/bridgetown-core/test/features/test_site_configuration.rb b/bridgetown-core/test/features/test_site_configuration.rb index eb41eb8d2..0177870ef 100644 --- a/bridgetown-core/test/features/test_site_configuration.rb +++ b/bridgetown-core/test/features/test_site_configuration.rb @@ -59,7 +59,7 @@ class TestSiteConfiguration < BridgetownFeatureTest context "future posts" do should "not output past site time with future: false" do create_directory "_posts" - create_page "index.html", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" + create_page "index.liquid", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" create_page "_posts/entry1.md", "content for entry 1", date: "2017-12-31", title: "entry1" create_page "_posts/entry2.md", "content for entry 2", date: "2027-01-31", title: "entry2" @@ -74,7 +74,7 @@ class TestSiteConfiguration < BridgetownFeatureTest should "output past site time with future: true" do create_directory "_posts" - create_page "index.html", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" + create_page "index.liquid", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" create_page "_posts/entry1.md", "content for entry 1", date: "2017-12-31", title: "entry1" create_page "_posts/entry2.md", "content for entry 2", date: "2027-01-31", title: "entry2" @@ -89,7 +89,7 @@ class TestSiteConfiguration < BridgetownFeatureTest should "output past site time with future CLI flag" do create_directory "_posts" - create_page "index.html", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" + create_page "index.liquid", "site time: {{ site.time | date: '%Y-%m-%d' }}", title: "Simple test" create_page "_posts/entry1.md", "content for entry 1", date: "2017-12-31", title: "entry1" create_page "_posts/entry2.md", "content for entry 2", date: "2027-01-31", title: "entry2" diff --git a/bridgetown-core/test/plugin_content/layouts/example/overridden_layout.html b/bridgetown-core/test/plugin_content/layouts/example/overridden_layout.html index 5d8a9a1ac..f95da6c42 100644 --- a/bridgetown-core/test/plugin_content/layouts/example/overridden_layout.html +++ b/bridgetown-core/test/plugin_content/layouts/example/overridden_layout.html @@ -1,4 +1,4 @@ --- --- :This layout content should NOT come through: -{{ content }} \ No newline at end of file +<%= yield %> \ No newline at end of file diff --git a/bridgetown-core/test/plugin_content/layouts/example/test_layout.html b/bridgetown-core/test/plugin_content/layouts/example/test_layout.html index e0ba0e03f..370b4ae98 100644 --- a/bridgetown-core/test/plugin_content/layouts/example/test_layout.html +++ b/bridgetown-core/test/plugin_content/layouts/example/test_layout.html @@ -1,4 +1,4 @@ --- --- :This layout content should come through: -{{ content }} \ No newline at end of file +<%= yield %> \ No newline at end of file diff --git a/bridgetown-core/test/source/_config.dev.toml b/bridgetown-core/test/source/_config.dev.toml deleted file mode 100644 index 7ac863f82..000000000 --- a/bridgetown-core/test/source/_config.dev.toml +++ /dev/null @@ -1,2 +0,0 @@ -baseurl = "/you-beautiful-blog-you" -title = "My magnificent site, wut" diff --git a/bridgetown-core/test/source/src/_layouts/example/overridden_layout.html b/bridgetown-core/test/source/src/_layouts/example/overridden_layout.liquid similarity index 100% rename from bridgetown-core/test/source/src/_layouts/example/overridden_layout.html rename to bridgetown-core/test/source/src/_layouts/example/overridden_layout.liquid diff --git a/bridgetown-core/test/source/src/_methods/configuration.md b/bridgetown-core/test/source/src/_methods/configuration.md index 4456821f8..4c5d95821 100644 --- a/bridgetown-core/test/source/src/_methods/configuration.md +++ b/bridgetown-core/test/source/src/_methods/configuration.md @@ -1,6 +1,7 @@ --- title: "Bridgetown.configuration" whatever: foo.bar +template_engine: liquid --- Use `{{ page.title }}` to build a full configuration for use w/Bridgetown. diff --git a/bridgetown-core/test/source/src/plugin_content/components.html b/bridgetown-core/test/source/src/plugin_content/components.liquid similarity index 100% rename from bridgetown-core/test/source/src/plugin_content/components.html rename to bridgetown-core/test/source/src/plugin_content/components.liquid diff --git a/bridgetown-core/test/source/src/plugin_content/layouts.html b/bridgetown-core/test/source/src/plugin_content/layouts.html deleted file mode 100644 index 66aedbddf..000000000 --- a/bridgetown-core/test/source/src/plugin_content/layouts.html +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: Components from Plugins -layout: example/test_layout ---- - -:{% render "example/this_should_work" %}: - -:{% render "example/this_should_get_overridden" %}: diff --git a/bridgetown-core/test/source/src/plugin_content/layouts.serb b/bridgetown-core/test/source/src/plugin_content/layouts.serb new file mode 100644 index 000000000..d165738dd --- /dev/null +++ b/bridgetown-core/test/source/src/plugin_content/layouts.serb @@ -0,0 +1,8 @@ +--- +title: Components from Plugins +layout: example/test_layout +--- + +:{%= liquid_render "example/this_should_work" %}: + +:{%= liquid_render "example/this_should_get_overridden" %}: diff --git a/bridgetown-core/test/test_configuration.rb b/bridgetown-core/test/test_configuration.rb index 0949750bb..7818742b7 100644 --- a/bridgetown-core/test/test_configuration.rb +++ b/bridgetown-core/test/test_configuration.rb @@ -247,9 +247,7 @@ def default_config_fixture(overrides = {}) setup do @paths = { default: site_root_dir("bridgetown.config.yml"), - other: site_root_dir("_config.live.yml"), - toml: site_root_dir("_config.dev.toml"), - empty: site_root_dir(""), + other: site_root_dir("bridgetown_config.other.yml"), } end @@ -288,14 +286,6 @@ def default_config_fixture(overrides = {}) default_config_fixture({ config: @paths[:other] }) end - should "load default config if path passed is empty" do - allow(Bridgetown::YAMLParser).to receive(:load_file).with(@paths[:default]).and_return({}) - allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") - assert_equal \ - site_configuration("config" => [@paths[:empty]]), - default_config_fixture({ "config" => [@paths[:empty]] }) - end - should "load multiple config files" do allow(Bridgetown::YAMLParser).to receive(:load_file).with(@paths[:default]).and_return({}) allow(Bridgetown::YAMLParser).to receive(:load_file).with(@paths[:other]).and_return({}) diff --git a/bridgetown-core/test/test_filters.rb b/bridgetown-core/test/test_filters.rb index a2097a6b3..8343b9b28 100644 --- a/bridgetown-core/test/test_filters.rb +++ b/bridgetown-core/test/test_filters.rb @@ -888,17 +888,18 @@ def to_liquid "date" => "2008-02-02 00:00:00 +0000", "summary" => "This should be published.", "data" => { - "ruby3" => "groovy", - "layout" => "default", - "title" => "Publish", - "category" => "publish_test", - "categories" => [ + "ruby3" => "groovy", + "layout" => "default", + "title" => "Publish", + "category" => "publish_test", + "categories" => [ "publish_test", ], - "tags" => [], - "locale" => "en", - "date" => "2008-02-02 00:00:00 +0000", - "slug" => "published", + "tags" => [], + "locale" => "en", + "date" => "2008-02-02 00:00:00 +0000", + "slug" => "published", + "template_engine" => "erb", }, "absolute_url" => "http://example.com/base/publish_test/2008/02/02/published/", "collection" => "posts", diff --git a/bridgetown-core/test/test_generated_page.rb b/bridgetown-core/test/test_generated_page.rb index 11749091d..64d4a09be 100644 --- a/bridgetown-core/test/test_generated_page.rb +++ b/bridgetown-core/test/test_generated_page.rb @@ -99,6 +99,7 @@ def render_and_write "an entry in 'site.generated_pages' array" do @page.content = "{{ site.title }}" @page.data["permalink"] = "/virtual-about/" + @page.data["template_engine"] = "liquid" @site.generated_pages << @page render_and_write diff --git a/bridgetown-core/test/test_new_command.rb b/bridgetown-core/test/test_new_command.rb index e197fce6d..0b20e692c 100644 --- a/bridgetown-core/test/test_new_command.rb +++ b/bridgetown-core/test/test_new_command.rb @@ -107,7 +107,7 @@ def static_template_files should "copy the static files for postcss configuration in site template to the new directory" do postcss_config_files = ["/postcss.config.js", "/frontend/styles/index.css"] - postcss_template_files = static_template_files + postcss_config_files + template_config_files + liquid_config_files + esbuild_config_files + postcss_template_files = static_template_files + postcss_config_files + template_config_files + erb_config_files + esbuild_config_files capture_output do Bridgetown::Commands::Base.start(argumentize(@args)) diff --git a/bridgetown-core/test/test_site.rb b/bridgetown-core/test/test_site.rb index b1795d4dc..b2737a5d0 100644 --- a/bridgetown-core/test/test_site.rb +++ b/bridgetown-core/test/test_site.rb @@ -151,7 +151,7 @@ class TestSite < BridgetownUnitTest application.coffee bar.html coffeescript.coffee - components.html + components.liquid contacts.html deal.with.dots.html dynamic_file.php @@ -161,7 +161,7 @@ class TestSite < BridgetownUnitTest humans.txt index.html info.md - layouts.html + layouts.serb layouts_override.html main.scss page_from_a_plugin.html