bridgetownrb / bridgetown-view-component Goto Github PK
View Code? Open in Web Editor NEWAdd support for GitHub's ViewComponent library to your Bridgetown sites.
License: MIT License
Add support for GitHub's ViewComponent library to your Bridgetown sites.
License: MIT License
I created a new Bridgetown project today and added ViewComponent the way I usually do but ran into an error I had not seen on my other website, which was using the same set up.
/Users/andrew.mason/Github/snowpack-starter/src/_components/base_component.rb:4:in `<class:BaseComponent>': uninitialized constant Rails::VERSION (NameError)
After some investigation, I think this commit may have been the issue..
I tried a few things to get rid of the error like defining Rails::VERSION
(before I saw the commit above) but ran into errors like:
/Users/andrew.mason/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/view_component-2.47.0/lib/view_component/base.rb:531:in `initialize_parameter_names':
s/module (TypeError)
I resolved the issue for now by locking view_component
to < 2.47.0
since it works fine in 2.46.0
.
group :bridgetown_plugins do
gem "bridgetown-view-component", "~> 0.7.0"
gem "view_component", "< 2.47.0"
end
Wasn't sure if the best plan was to find a way to stub this out or to open an upstream issue. WDYT?
I can provide code samples on request.
Attempting to upgrade the view_component
gem and running into an issue.
Bridgetown] Exception raised: NoMethodError
[Bridgetown] undefined method `resource' for #<IconComponent:0x00000001113f4398 #... >>>
[Bridgetown] 1: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-view-component-2.0.0/lib/bridgetown-view-component/bridgetown/view_component_helpers.rb:54:in `method_missing'
[Bridgetown] 2: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-routes-1.3.4/lib/bridgetown-routes/view_helpers.rb:19:in `roda_app'
[Bridgetown] 3: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-routes-1.3.4/lib/bridgetown-routes/view_helpers.rb:23:in `request'
[Bridgetown] 4: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-view-component-2.0.0/lib/bridgetown-view-component/bridgetown/view_component_helpers.rb:52:in `method_missing'
[Bridgetown] 5: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/view_component-3.12.1/lib/view_component/base.rb:321:in `maybe_escape_html'
[Bridgetown] 6: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/view_component-3.12.1/lib/view_component/base.rb:336:in `safe_render_template_for'
[Bridgetown] 7: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/view_component-3.12.1/lib/view_component/base.rb:109:in `render_in'
[Bridgetown] 8: /Users/drbragg/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bridgetown-core-1.3.4/lib/bridgetown-core/ruby_template_view.rb:35:in `render'
...
Doing a bit of digging I found a change in VC 3.9 that might(?) be a source of the problem: ViewComponent/view_component#1950 specifically the changes to lib/view_component/base.rb:310
.
It looks like when request
is called it's calling the request
method in bridgetown-routes/lib/bridgetown-routes/view_helpers.rb:22
which looks at view.resource&.roda_app
. In my case the "view" in question appears to be the component instance.
If I add
def resource
nil
end
to the BaseComponent
everything boots and renders as normal. Not 100% sure if this is the correct work around it just works for me.
bridgetown: 1.3.4
bridgetown-view-component: 2.0
view_component: >= 3.9.0
config/initializers.rb
Bridgetown.configure do |config|
init :"bridgetown-view-component" do
ViewComponent::Base.config.view_component_path = "src/_components"
end
init :ssr
init :"bridgetown-routes"
end
Let me know if there's any other information I can provide that might be helpful.
Hi I am following the quick installation guide, on a fresh project.
I added the example's view component and nothing else. But when I try to start server I encounter the following error:
Versions of all gems
GEM
remote: https://rubygems.org/
specs:
actionview (7.0.4)
activesupport (= 7.0.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.4)
activesupport (= 7.0.4)
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
amazing_print (1.4.0)
bridgetown (1.1.0)
bridgetown-builder (= 1.1.0)
bridgetown-core (= 1.1.0)
bridgetown-paginate (= 1.1.0)
bridgetown-builder (1.1.0)
bridgetown-core (= 1.1.0)
bridgetown-core (1.1.0)
activemodel (>= 6.0, < 8.0)
activesupport (>= 6.0, < 8.0)
addressable (~> 2.4)
amazing_print (~> 1.2)
colorator (~> 1.0)
erubi (~> 1.9)
faraday (~> 1.0)
faraday_middleware (~> 1.0)
hash_with_dot_access (~> 1.2)
i18n (~> 1.0)
kramdown (~> 2.1)
kramdown-parser-gfm (~> 1.0)
liquid (~> 5.0)
listen (~> 3.0)
rake (>= 13.0)
roda (~> 3.46)
rouge (~> 3.0)
serbea (~> 1.0)
terminal-table (~> 1.8)
thor (~> 1.1)
tilt (~> 2.0)
webrick (~> 1.7)
zeitwerk (~> 2.5)
bridgetown-paginate (1.1.0)
bridgetown-core (= 1.1.0)
bridgetown-view-component (1.0.0)
actionview (>= 6.0)
bridgetown (>= 1.0.0.beta3, < 2.0)
view_component (>= 2.49)
builder (3.2.4)
colorator (1.1.0)
concurrent-ruby (1.1.10)
crass (1.0.6)
erubi (1.11.0)
faraday (1.10.2)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
ffi (1.15.5)
hash_with_dot_access (1.2.0)
activesupport (>= 5.0.0, < 8.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (5.4.0)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.19.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
method_source (1.0.0)
minitest (5.16.3)
multipart-post (2.2.3)
nio4r (2.5.8)
nokogiri (1.13.9-arm64-darwin)
racc (~> 1.4)
public_suffix (5.0.0)
puma (5.6.5)
nio4r (~> 2.0)
racc (1.6.0)
rack (3.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.5)
roda (3.61.0)
rack
rouge (3.30.0)
ruby2_keywords (0.0.5)
serbea (1.0.1)
activesupport (>= 6.0)
erubi (>= 1.10)
tilt (~> 2.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.2.1)
tilt (2.0.11)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (1.8.0)
view_component (2.75.0)
activesupport (>= 5.0.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
webrick (1.7.0)
zeitwerk (2.6.4)
PLATFORMS
arm64-darwin-22
DEPENDENCIES
bridgetown (~> 1.1.0)
bridgetown-view-component (~> 1.0)
puma (~> 5.6)
BUNDLED WITH
2.3.24
As an experiment I also downloaded lookbook docs, that are build with bridgetown too.
When I upgraded the core gem to v1.1.0 I had the same issue. Their repo is still using bridgetown-v1.0.0.
Thanks in advance and I am glad to help with any more information you may need.
Hello,
I tried this plugins in collaboration with the bridgetown-haml plugins to build the views in HAML.
I got the following error :
There was an error when building the site:
ViewComponent::TemplateError: Couldn't find a template file or inline render method for Shared::Header
when the template file is header.haml
However it works correctly with hearder.erb
I tried initializing the view-component plugin before and after the haml plugin but it didn't change the result.
Thanks for your help.
I see you are using view_component 2.0 and may want to upgrade to view_component 3
Most ActionView helpers are blocked from use within Bridgetown (because some don't work well or have conflicts), but this is configurable and should be documented so folks can tweak accordingly.
When adding this gem to a Bridgetown v1.2.0 project I get a bunch of deprecation warnings in the console.
[Bridgetown] Deprecation: The Bridgetown::ViewComponent plugin should switch from using `new_source_manifest' to the `source_manifest` initializer method
[Bridgetown] Deprecation: The Bridgetown::ViewComponent plugin should switch from using `add_source_manifest' to the `source_manifest` initializer method
[Bridgetown] Initializing: The `bridgetown-view-component' initializer could not be found
[Bridgetown] Deprecation: The Bridgetown::ViewComponent plugin should switch from using `new_source_manifest' to the `source_manifest` initializer method
[Bridgetown] Deprecation: The Bridgetown::ViewComponent plugin should switch from using `add_source_manifest' to the `source_manifest` initializer method
[Bridgetown] Initializing: The `bridgetown-view-component' initializer could not be found
Relevant code:
# Gemfile
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "bridgetown", "1.2.0.beta4"
gem "bridgetown-view-component"
gem "view_component", "< 2.75"
group :development do
gem "puma", "~> 5.6"
end
# config/initializers.rb
Bridgetown.configure do |config|
permalink "pretty"
template_engine "erb"
init :"bridgetown-view-component"
end
Hi,
I've created a component that works on first render, but when I update it nothing changes. Not with automatic reloading, not with manual reload, not when restarting the server. The only thing that helps is deleting the output directory and starting bridgetown again, but after that it doesn't render on changes either.
I am using gem "bridgetown-view-component", "~> 2.0"
and I've done all the setup from the docs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.