Skip to content

Commit

Permalink
Merge branch 'main' into roda-documentation-and-plugin-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite authored Jan 3, 2025
2 parents d2f8fc8 + 8b54e1c commit 7476df4
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 195 deletions.
1 change: 1 addition & 0 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module Bridgetown
autoload :Slot, "bridgetown-core/slot"
autoload :StaticFile, "bridgetown-core/static_file"
autoload :Transformable, "bridgetown-core/concerns/transformable"
autoload :Viewable, "bridgetown-core/concerns/viewable"
autoload :Utils, "bridgetown-core/utils"
autoload :VERSION, "bridgetown-core/version"
autoload :Watcher, "bridgetown-core/watcher"
Expand Down
3 changes: 2 additions & 1 deletion bridgetown-core/lib/bridgetown-core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def entry_filter
#
# @return [String]
def inspect
"#<#{self.class} @label=#{label} resources=#{resources}>"
"#<#{self.class} #{label}: #{resources.count} metadata=#{metadata.inspect} " \
"static_files: #{static_files.count}>"
end

# Produce a sanitized label name
Expand Down
147 changes: 0 additions & 147 deletions bridgetown-core/lib/bridgetown-core/commands/doctor.rb

This file was deleted.

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

module Bridgetown
# This mixin for Bridgetown components allows you to provide front matter and render
# the component template via the layouts transformation pipeline, which can be called
# from any Roda route
module Viewable
include Bridgetown::RodaCallable
include Bridgetown::Transformable

def site
@site ||= Bridgetown::Current.site
end

def data
@data ||= HashWithDotAccess::Hash.new
end

def front_matter(&block)
Bridgetown::FrontMatter::RubyFrontMatter.new(data:).tap { _1.instance_exec(&block) }
end

def relative_path = self.class.source_location.delete_prefix("#{site.root_dir}/")

# Render the component template in the layout specified in your front matter
#
# @param app [Roda]
def render_in_layout(app)
render_in(app) => rendered_output

site.validated_layouts_for(self, data.layout).each do |layout|
transform_with_layout(layout, rendered_output, self) => rendered_output
end

rendered_output
end

# Pass a block of front matter and render the component template in layouts
#
# @param app [Roda]
def render_with(app, &)
front_matter(&)
render_in_layout(app)
end
end
end
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Helpers
include ::Streamlined::Helpers
include Inclusive

# @return [Bridgetown::RubyTemplateView]
# @return [Bridgetown::RubyTemplateView, Bridgetown::Component]
attr_reader :view

# @return [Bridgetown::Site]
Expand All @@ -22,7 +22,7 @@ class Helpers
# @return [Bridgetown::Foundation::SafeTranslations]
packages def translate_package = [Bridgetown::Foundation::Packages::SafeTranslations]

# @param view [Bridgetown::RubyTemplateView]
# @param view [Bridgetown::RubyTemplateView, Bridgetown::Component]
# @param site [Bridgetown::Site]
def initialize(view = nil, site = nil)
@view = view
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/roda/plugins/bridgetown_ssr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.load_dependencies(app, opts = { sessions: false })
# This lets us return callable objects directly in Roda response blocks
app.plugin :custom_block_results
app.handle_block_result(Bridgetown::RodaCallable) do |callable|
callable.(self)
request.send :block_result_body, callable.(self)
end

return unless opts[:sessions]
Expand Down
3 changes: 2 additions & 1 deletion bridgetown-core/test/ssr/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require "bridgetown-core/rack/boot"

Bridgetown::Rack.boot

require_relative "src/_components/UseRoda" # normally Zeitwerk would take care of this for us
require_relative "src/_components/page_me" # normally Zeitwerk would take care of this for us
require_relative "src/_components/use_roda" # normally Zeitwerk would take care of this for us

run RodaApp.freeze.app # see server/roda_app.rb
4 changes: 4 additions & 0 deletions bridgetown-core/test/ssr/server/routes/render_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ class Routes::RenderResource < Bridgetown::Rack::Routes
r.get "render_component", String do |title|
UseRoda.new(title:)
end

r.get "render_view", String do |title|
PageMe.new(title:)
end
end
end
9 changes: 9 additions & 0 deletions bridgetown-core/test/ssr/src/_components/page_me.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2><%= @title %></h2>

<%= markdownify do %>
* Port <%= @port_number %>

<%= render Shared::Stuff.new(wild: 123) do %>
_ya think?_
<% end %>
<% end %>
20 changes: 20 additions & 0 deletions bridgetown-core/test/ssr/src/_components/page_me.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class PageMe < Bridgetown::Component
include Bridgetown::Viewable

def initialize(title:) # rubocop:disable Lint/MissingSuper
@title = title.upcase

data.title = @title
end

def call(app)
@port_number = app.request.port

render_with(app) do
layout :page
page_class "some-extras"
end
end
end
11 changes: 11 additions & 0 deletions bridgetown-core/test/ssr/src/_components/shared/stuff.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class Shared::Stuff < Bridgetown::Component
def initialize(wild:) # rubocop:disable Lint/MissingSuper
@wild = wild * 2
end

def template
"Well that was #{@wild}!#{content}"
end
end
1 change: 1 addition & 0 deletions bridgetown-core/test/ssr/src/_data/site_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title: So Awesome
5 changes: 5 additions & 0 deletions bridgetown-core/test/ssr/src/_layouts/default.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<title><%= data.title %> | <%= site.metadata.title %></title>

<body class="<%= data.layout %> <%= data.page_class %>">
<%= yield %>
</body>
7 changes: 7 additions & 0 deletions bridgetown-core/test/ssr/src/_layouts/page.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: default
---

<h1><%= data.title %></h1>

<%= yield %>
41 changes: 0 additions & 41 deletions bridgetown-core/test/test_doctor_command.rb

This file was deleted.

11 changes: 11 additions & 0 deletions bridgetown-core/test/test_ssr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,16 @@ def site

assert_equal({ "saved" => "Save this value: abc12356" }, JSON.parse(last_response.body))
end

should "return rendered view" do
get "/render_view/Page_Me"

assert last_response.ok?
assert_includes last_response.body, "<title>PAGE_ME | So Awesome</title>"
assert_includes last_response.body, "<body class=\"page some-extras\">"
assert_includes last_response.body, "<h1>PAGE_ME</h1>"
assert_includes last_response.body, "<ul>\n <li>Port 80</li>\n</ul>"
assert_includes last_response.body, "<p>Well that was 246!\n <em>ya think?</em></p>"
end
end
end
3 changes: 1 addition & 2 deletions bridgetown-website/src/_docs/command-line-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Available commands are:
* `bridgetown new PATH` - Creates a new Bridgetown site at the specified path with a default configuration and typical site folder structure.
* Use the `--apply=` or `-a` option to [apply an automation](/docs/automations) to the new site.
* Use the `--configure=` or `-c` option to [apply one or more bundled configurations](/docs/bundled-configurations) to the new site.
* Use the `-t` option to choose ERB or Serbea templates instead of Liquid (aka `-t erb`).
* Use the `-t` option to choose Serbea or Liquid templates instead of ERB (aka `-t serbea`).
* Use the `--use-sass` option to configure your project to support Sass.
* `bin/bridgetown start` or `s` - Boots the Rack-based server (using Puma) at `localhost:4000`. In development, you'll get live reload functionality as long as `{% live_reload_dev_js %}` or `<%= live_reload_dev_js %>` is in your HTML head.
* `bin/bridgetown deploy` - Ensures that all frontend assets get built alongside the published Bridgetown output. This is the command you'll want to use for [deployment](/docs/deployment).
Expand All @@ -29,7 +29,6 @@ Available commands are:
* `bin/bridgetown configure CONFIGURATION` - Run a [bundled configuration](/docs/bundled-configurations) for your existing site. Invoke without arguments to see all available configurations.
* `bin/bridgetown date` - Displays the current date and time so you can copy'n'paste it into your front matter.
* `bin/bridgetown help` - Shows help, optionally for a given subcommand, e.g. `bridgetown help build`.
* `bin/bridgetown doctor` - Outputs any deprecation or configuration issues.
* `bin/bridgetown clean` - Removes all generated files: destination folder, metadata file, and Bridgetown caches.
* `bin/bridgetown esbuild ACTION` - Allows you to perform actions such as `update` on your project's esbuild configuration. Invoke without arguments to see all available actions.
{% endraw %}
Expand Down
Loading

0 comments on commit 7476df4

Please sign in to comment.