Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass level to HeadlineView component #2480

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/components/alchemy/ingredients/headline_view.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module Alchemy
module Ingredients
class HeadlineView < BaseView
def initialize(ingredient, level: nil, html_options: {})
super(ingredient, html_options: html_options)
@level = level
end

def call
content_tag "h#{ingredient.level}",
content_tag "h#{@level || ingredient.level}",
ingredient.value,
id: ingredient.dom_id.presence,
class: [
Expand Down
15 changes: 0 additions & 15 deletions app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,5 @@ def element_tags_attributes(element, options = {})

{"data-element-tags" => options[:formatter].call(element.tag_list)}
end

def ingredient_view_deprecation_notice(ingredient, file)
Alchemy::Deprecation.warn(<<~WARN)
rendering `alchemy/ingredients/#{file.split("/").last.sub(/^_/, "")}` partial is deprecated.

Please render the view component directly instead:

<%= render ingredient.as_view_component %>

or use the `el.render` helper inside a `element_view_for` helper:

<%= el.render(:#{ingredient.role}) %>

WARN
end
end
end
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_audio_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(audio_view, __FILE__) -%>
<%= render audio_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_boolean_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(boolean_view, __FILE__) -%>
<%= render boolean_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_datetime_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(datetime_view, __FILE__) -%>
<%= render datetime_view.as_view_component(
**local_assigns.slice(:options)
) -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_file_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(file_view, __FILE__) -%>
<%= render file_view.as_view_component(
**local_assigns.slice(:options),
**local_assigns.slice(:html_options)
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_headline_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(headline_view, __FILE__) -%>
<%= render headline_view.as_view_component(
**local_assigns.slice(:options),
**local_assigns.slice(:html_options)
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_html_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(html_view, __FILE__) -%>
<%= render html_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_link_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(link_view, __FILE__) -%>
<%= render link_view.as_view_component(
**local_assigns.slice(:options),
**local_assigns.slice(:html_options)
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_node_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(node_view, __FILE__) -%>
<%= render node_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_page_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(page_view, __FILE__) -%>
<%= render page_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_picture_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(picture_view, __FILE__) -%>
<%= render picture_view.as_view_component(
**local_assigns.slice(:options),
**local_assigns.slice(:html_options)
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_richtext_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(richtext_view, __FILE__) -%>
<%= render richtext_view.as_view_component(
**local_assigns.slice(:options)
) -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_select_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(select_view, __FILE__) -%>
<%= render select_view.as_view_component -%>
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_text_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%- ingredient_view_deprecation_notice(text_view, __FILE__) -%>
<%= render text_view.as_view_component(
**local_assigns.slice(:options),
**local_assigns.slice(:html_options)
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/_video_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<%- ingredient_view_deprecation_notice(video_view, __FILE__) -%>
<%= render video_view.as_view_component -%>
8 changes: 8 additions & 0 deletions spec/views/alchemy/ingredients/headline_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
expect(rendered).to have_content("Hello")
end

context "with level option passed" do
it "renders headline for given level" do
render(ingredient, options: {level: 1})
expect(rendered).to have_selector("h1")
expect(rendered).to have_content("Hello")
end
end

context "with dom_id" do
it "adds id" do
render ingredient
Expand Down