Skip to content

Commit

Permalink
Upgrade for Bridgetown 1.2 initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Jan 22, 2023
1 parent 285430b commit 39d46b7
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 31 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

# 0.7.0 / 2021-06-01
## 2.0.0 / 2023-01-22

* Upgrade for Bridgetown 1.2 initializers

## 1.0.0 / 2022-03-20

* Update release to support Bridgetown 1.0

## 0.7.0 / 2021-06-01

* Official release supporting Bridgetown 0.21.
2 changes: 1 addition & 1 deletion bridgetown-view-component.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.7.0"

spec.add_dependency "bridgetown", ">= 1.0.0.beta3", "< 2.0"
spec.add_dependency "bridgetown", ">= 1.2.0.beta5", "< 2.0"
spec.add_dependency "view_component", ">= 2.49"
spec.add_dependency "actionview", ">= 6.0"

Expand Down
33 changes: 17 additions & 16 deletions lib/bridgetown-view-component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,26 @@ module ViewComponent
"bridgetown-view-component/bridgetown/component_validation"
end

# Set up the test components source manifest
Bridgetown::PluginManager.new_source_manifest(
origin: Bridgetown::ViewComponent,
components: File.expand_path("../components", __dir__)
)
Bridgetown.initializer :"bridgetown-view-component" do |config|
config.source_manifest(
origin: Bridgetown::ViewComponent,
components: File.expand_path("../components", __dir__)
)

# Add a few methods to Bridgetown's Ruby template superclasses
[Bridgetown::RubyTemplateView, Bridgetown::Component].each do |klass|
klass.class_eval do
def lookup_context
HashWithDotAccess::Hash.new(variants: [])
end
# Add a few methods to Bridgetown's Ruby template superclasses
[Bridgetown::RubyTemplateView, Bridgetown::Component].each do |klass|
klass.class_eval do
def lookup_context
HashWithDotAccess::Hash.new(variants: [])
end

def view_renderer
nil
end
def view_renderer
nil
end

def view_flow
nil
def view_flow
nil
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ def render(item, options = {}, &block)
end

def helpers
@helpers ||= Bridgetown::RubyTemplateView::Helpers.new(self, @view_context.site)
@helpers ||= Bridgetown::RubyTemplateView::Helpers.new(
self, view_context&.site || Bridgetown::Current.site
)
end

def method_missing(method, *args, &block)
def method_missing(method, *args, **kwargs, &block)
if helpers.respond_to?(method.to_sym)
helpers.send method.to_sym, *args, &block
helpers.send method.to_sym, *args, **kwargs, &block
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bridgetown-view-component/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Bridgetown
module ViewComponent
VERSION = "1.0.0"
VERSION = "2.0.0"
end
end
12 changes: 8 additions & 4 deletions spec/bridgetown-view-component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"root_dir" => root_dir,
"source" => source_dir,
"destination" => dest_dir,
}, overrides))
}, overrides)).tap do |conf|
conf.run_initializers! context: :static
end
end
let(:metadata_overrides) { {} }
let(:metadata_defaults) do
Expand All @@ -30,8 +32,10 @@
FileUtils.rm(source_dir("_data/site_metadata.yml"))
end

#TODO: add tests!
it "outputs the sample component" do
expect(contents).to match "#TODO"
it "outputs the rendered ViewComponent" do
expect(contents).to match "Greetings Bridgetown"
expect(contents).to match "<hr>\n"
expect(contents).to match "<strong>Post 1</strong> <span>-&gt;</span>"
expect(contents).to match "<strong>Post 2</strong> <span>-&gt;</span>"
end
end
3 changes: 3 additions & 0 deletions spec/fixtures/config/initializers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bridgetown.configure do
init :"bridgetown-view-component"
end
9 changes: 9 additions & 0 deletions spec/fixtures/src/_components/hello_vc.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Greetings <%= @name %>
<%= tag.hr %>

<ul>
<% posts.each do |post| %>
<li><%= markdownify post %></li>
<% end %>
</ul>
10 changes: 10 additions & 0 deletions spec/fixtures/src/_components/hello_vc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class HelloVc < ViewComponent::Base
Bridgetown::ViewComponentHelpers.allow_rails_helpers :tag
include Bridgetown::ViewComponentHelpers

renders_many :posts

def initialize(name:)
@name = name
end
end
13 changes: 13 additions & 0 deletions spec/fixtures/src/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
layout: default
---

Testing this plugin:

<%= render HelloVc.new(name: "Bridgetown") do |component |%>
<% ["Post 1", "Post 2"].each do |blog_post| %>
<% component.with_post do %>
**<%= blog_post %>** <span>-></span>
<% end %>
<% end %>
<% end %>
5 changes: 0 additions & 5 deletions spec/fixtures/src/index.html

This file was deleted.

6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

require "bridgetown"

Bridgetown.begin!

# rubocop:disable Lint/Void
Bridgetown::Site # resolve weird autoload issue
# rubocop:enable Lint/Void
require File.expand_path("../lib/bridgetown-view-component", __dir__)

Bridgetown.logger.log_level = :error
Expand Down

0 comments on commit 39d46b7

Please sign in to comment.