Skip to content

Commit

Permalink
Streamlined tweaks; components now automatically support syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Feb 3, 2024
1 parent 474c8b7 commit 14af05a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Bridgetown
class Component
include Bridgetown::Streamlined
extend Forwardable

def_delegators :@view_context, :liquid_render, :partial
Expand Down
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 @@ -148,6 +148,7 @@ def run_initializers!(context:) # rubocop:todo Metrics/AbcSize, Metrics/Cyclomat
dsl = ConfigurationDSL.new(scope: self, data: self)
dsl.instance_variable_set(:@context, context)
dsl.instance_exec(dsl, &init_init.block)
dsl._run_builtins!
self.url = cached_url if cached_url # restore local development URL if need be

setup_load_paths! appending: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ def _setup_initializer(name:, require_gem:, require_initializer:)
def _in_require_denylist?(name)
REQUIRE_DENYLIST.include?(name.to_sym)
end

# Initializers that are part of the Bridgetown boot sequence. Site owners can override defaults
# by running any of these manually…init is no-op if the initializer was already run.
def _run_builtins!
init :streamlined
end
end
end
end
16 changes: 2 additions & 14 deletions bridgetown-core/lib/bridgetown-core/converters/ruby_templates.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# frozen_string_literal: true

module Bridgetown
module Streamlined
include ::Streamlined::Renderable
include ERBCapture

def helper(name, &helper_block)
self.class.define_method(name) do |*args, **kwargs, &block|
helper_block.call(*args, **kwargs, &block)
end
end
alias_method :macro, :helper
end
require "streamlined/renderable"

module Bridgetown
class PureRubyView < ERBView
include Bridgetown::Streamlined

def render(item = nil, **options, &block) # rubocop:disable Metrics
return @_erbout if !block && options.empty? && item.nil?

Expand Down
4 changes: 3 additions & 1 deletion bridgetown-core/lib/bridgetown-core/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require "streamlined/helpers"

module Bridgetown
class RubyTemplateView
class Helpers
include Bridgetown::Filters
include Bridgetown::Filters::FromLiquid
include Streamlined::Helpers
include ::Streamlined::Helpers

# @return [Bridgetown::RubyTemplateView]
attr_reader :view
Expand Down
16 changes: 16 additions & 0 deletions bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# frozen_string_literal: true

require "digest"
require "streamlined/helpers"
require "streamlined/renderable"

module Bridgetown
module Streamlined
include ::Streamlined::Renderable
include ERBCapture

def helper(name, &helper_block)
self.class.define_method(name) do |*args, **kwargs, &block|
helper_block.call(*args, **kwargs, &block)
end
end
alias_method :macro, :helper
end

class RubyTemplateView
require "bridgetown-core/helpers"

include Bridgetown::Streamlined

attr_reader :layout, :resource, :paginator, :site, :content
alias_method :page, :resource

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class RubyHtmlText < Bridgetown::Component
include Bridgetown::Streamlined

def template
# blub = ->(input, str, replace_str) { input.sub(str, replace_str) }

Expand Down

0 comments on commit 14af05a

Please sign in to comment.