Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bridgetownrb/bridgetown
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed May 16, 2022
2 parents ae72558 + 33304fa commit 1909ec7
Show file tree
Hide file tree
Showing 32 changed files with 428 additions and 57 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ group :test do
gem "minitest-profile"
gem "minitest-reporters"
gem "nokogiri", "~> 1.7"
gem "rack-test"
gem "rspec"
gem "rspec-mocks"
gem "rubocop-bridgetown", "~> 0.3.0", require: false
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-builder/lib/bridgetown-builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Builders
# SiteBuilder is the superclass sites can subclass to create any number of
# builders, but if the site hasn't defined it explicitly, this is a no-op
if defined?(SiteBuilder)
SiteBuilder.descendants.map do |c|
SiteBuilder.descendants.sort.map do |c|
c.new(c.name, site).build_with_callbacks
end
end
Expand Down
10 changes: 10 additions & 0 deletions bridgetown-builder/lib/bridgetown-builder/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
module Bridgetown
module Builders
class PluginBuilder
include Bridgetown::Prioritizable

self.priorities = {
highest: 100,
high: 10,
normal: 0,
low: -10,
lowest: -100,
}.freeze

include DSL::Generators
include DSL::Helpers
include DSL::Hooks
Expand Down
15 changes: 14 additions & 1 deletion bridgetown-builder/test/test_generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@
require "helper"

class GeneratorBuilder < Builder
priority :low

def build
generator do
site.data[:site_metadata][:title] = "Test Title"
end
end
end

class GeneratorBuilder2 < Builder
def build
generator do
site.data[:site_metadata][:title] = "Test Title 2"
end
end
end

class TestGenerators < BridgetownUnitTest
context "creating a generator" do
setup do
Bridgetown.sites.clear
@site = Site.new(site_configuration)
@builder = GeneratorBuilder.new("Generator Test", @site).build_with_callbacks
@builders = [GeneratorBuilder, GeneratorBuilder2].sort
@builders.each_with_index do |builder, index|
builder.new("Generator Test #{index}", @site).build_with_callbacks
end
end

should "be loaded on site setup" do
Expand Down
2 changes: 2 additions & 0 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def require_all(path)

# 3rd party
require "active_support"
require "active_support/core_ext/class/attribute"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/object/blank"
Expand Down Expand Up @@ -90,6 +91,7 @@ module Bridgetown
autoload :LogAdapter, "bridgetown-core/log_adapter"
autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
autoload :PluginManager, "bridgetown-core/plugin_manager"
autoload :Prioritizable, "bridgetown-core/concerns/prioritizable"
autoload :Publishable, "bridgetown-core/concerns/publishable"
autoload :Publisher, "bridgetown-core/publisher"
autoload :Reader, "bridgetown-core/reader"
Expand Down
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def create_site(new_site_path)
template("frontend/javascript/index.js.erb", "frontend/javascript/index.js")
template("src/index.md.erb", "src/index.md")
template("src/posts.md.erb", "src/posts.md")
copy_file("frontend/styles/syntax-highlighting.css")

case options["templates"]
when "erb"
Expand Down
3 changes: 3 additions & 0 deletions bridgetown-core/lib/bridgetown-core/commands/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def output_header(mode)
end

cli = Puma::CLI.new puma_args
cli.launcher.events.on_stopped do
Bridgetown::Hooks.trigger :site, :server_shutdown
end
cli.run
end

Expand Down
44 changes: 44 additions & 0 deletions bridgetown-core/lib/bridgetown-core/concerns/prioritizable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

module Bridgetown
module Prioritizable
module ClassMethods
# @!method priorities
# @return [Hash<Symbol, Object>]

# Get or set the priority of this class. When called without an
# argument it returns the priority. When an argument is given, it will
# set the priority.
#
# @param priority [Symbol] new priority (optional)
# Valid options are: `:lowest`, `:low`, `:normal`, `:high`, `:highest`
# @return [Symbol]
def priority(priority = nil)
@priority ||= nil
@priority = priority if priority && priorities.key?(priority)
@priority || :normal
end

# Spaceship is priority [higher -> lower]
#
# @param other [Class] The class to be compared.
# @return [Integer] -1, 0, 1.
def <=>(other)
priorities[other.priority] <=> priorities[priority]
end
end

def self.included(klass)
klass.extend ClassMethods
klass.class_attribute :priorities, instance_accessor: false
end

# Spaceship is priority [higher -> lower]
#
# @param other [object] The object to be compared.
# @return [Integer] -1, 0, 1.
def <=>(other)
self.class <=> other.class
end
end
end
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Configuration < HashWithDotAccess::Hash
"footnote_nr" => 1,
"show_warnings" => false,
"include_extraction_tags" => false,
"mark_highlighting" => true,
},
}.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def initialize(config)
@config["syntax_highlighter"] ||= config["highlighter"] || "rouge"
@config["syntax_highlighter_opts"] ||= {}
@config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
require "kramdown-parser-gfm" if @config["input"] == "GFM"
require_relative "../../kramdown/parser/gfm" if @config["input"] == "GFM"
end

def convert(content)
Expand Down
6 changes: 3 additions & 3 deletions bridgetown-core/lib/bridgetown-core/frontmatter_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def ensure_time!(set)
# @param path [String] the relative path of the resource
# @param collection [Symbol] :posts, :pages, etc.
#
# @returns [Hash] all default values (an empty hash if there are none)
# @return [Hash] all default values (an empty hash if there are none)
def all(path, collection)
defaults = {}

Expand Down Expand Up @@ -123,7 +123,7 @@ def strip_collections_dir(path)
# @param scope [Hash] the defaults set being asked about
# @param collection [Symbol] the collection of the resource being processed
#
# @returns [Boolean] whether either of the above conditions are satisfied
# @return [Boolean] whether either of the above conditions are satisfied
def applies_collection?(scope, collection)
!scope.key?("collection") || scope["collection"].eql?(collection.to_s)
end
Expand All @@ -132,7 +132,7 @@ def applies_collection?(scope, collection)
#
# @param set [Hash] the default value hash as defined in bridgetown.config.yml
#
# @returns [Boolean] if the set is valid and can be used
# @return [Boolean] if the set is valid and can be used
def valid?(set)
set.is_a?(Hash) && set["values"].is_a?(Hash)
end
Expand Down
36 changes: 36 additions & 0 deletions bridgetown-core/lib/bridgetown-core/kramdown/parser/gfm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Frozen-string-literal: true

require "kramdown-parser-gfm"

module Kramdown
module Parser
class GFM
MARK_DELIMITER = %r{(==|::)+}.freeze
MARK_MATCH = %r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m.freeze

# Monkey-patch GFM initializer to add our new mark parser
alias_method :_old_initialize, :initialize
def initialize(source, options)
_old_initialize(source, options)
@span_parsers << :mark if @options[:mark_highlighting]
end

def parse_mark
line_number = @src.current_line_number

@src.pos += @src.matched_size
el = Element.new(:html_element, "mark", {}, category: :span, line: line_number)
@tree.children << el

env = save_env
reset_env(src: Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number),
text_type: :text)
parse_spans(el)
restore_env(env)

el
end
define_parser(:mark, MARK_MATCH)
end
end
end
41 changes: 5 additions & 36 deletions bridgetown-core/lib/bridgetown-core/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,18 @@
module Bridgetown
class Plugin
extend ActiveSupport::DescendantsTracker
include Bridgetown::Prioritizable

PRIORITIES = {
low: -10,
self.priorities = {
highest: 100,
lowest: -100,
normal: 0,
high: 10,
normal: 0,
low: -10,
lowest: -100,
}.freeze

SourceManifest = Struct.new(:origin, :components, :content, :layouts, keyword_init: true)

# Get or set the priority of this plugin. When called without an
# argument it returns the priority. When an argument is given, it will
# set the priority.
#
# priority - The Symbol priority (default: nil). Valid options are:
# :lowest, :low, :normal, :high, :highest
#
# Returns the Symbol priority.
def self.priority(priority = nil)
@priority ||= nil
@priority = priority if priority && PRIORITIES.key?(priority)
@priority || :normal
end

# Spaceship is priority [higher -> lower]
#
# other - The class to be compared.
#
# Returns -1, 0, 1.
def self.<=>(other)
PRIORITIES[other.priority] <=> PRIORITIES[priority]
end

# Spaceship is priority [higher -> lower]
#
# other - The class to be compared.
#
# Returns -1, 0, 1.
def <=>(other)
self.class <=> other.class
end

# Initialize a new plugin. This should be overridden by the subclass.
#
# config - The Hash of configuration options.
Expand Down
5 changes: 5 additions & 0 deletions bridgetown-core/lib/bridgetown-core/rack/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class << self
attr_accessor :loaders_manager
end

# Start up the Roda Rack application and the Zeitwerk autoloaders. Ensure the
# Roda app is provided the preloaded Bridgetown site configuration. Handle
# any uncaught Roda errors.
#
# @param [Bridgetown::Rack::Roda] optional, defaults to the `RodaApp` constant
def self.boot(roda_app = nil)
self.loaders_manager =
Bridgetown::Utils::LoadersManager.new(Bridgetown::Current.preloaded_configuration)
Expand Down
Loading

0 comments on commit 1909ec7

Please sign in to comment.