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

Remove component CSS class name default #545

Merged
merged 1 commit into from
Oct 24, 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
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This provides a simpler alternative to nesting partials.
The recommended approach is to subclass Arbre::Component and implement a new builder method.

The builder_method defines the method that will be called to build this component
when using the DSL. The arguments passed into the builder_method will be passed
when using the DSL. The arguments passed into the builder_method will be passed
into the #build method for you.

For example:
Expand All @@ -66,7 +66,7 @@ class Panel < Arbre::Component
end
```

By default components are `div` tags with an HTML class corresponding to the component class name. This can be overridden by redefining the `tag_name` method.
By default, components are `div` tags. This can be overridden by redefining the `tag_name` method.

Several examples of Arbre components are [included in Active Admin](https://activeadmin.info/12-arbre-components.html)

Expand All @@ -76,7 +76,7 @@ An [Arbre::Context](http://www.rubydoc.info/gems/arbre/Arbre/Context) is an obje

```ruby
html = Arbre::Context.new do
panel "Hello World", id: "my-panel" do
panel "Hello World", class: "panel", id: "my-panel" do
span "Inside the panel"
text_node "Plain text"
end
Expand Down
14 changes: 0 additions & 14 deletions lib/arbre/component.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# frozen_string_literal: true
module Arbre
class Component < Arbre::HTML::Div

# By default components render a div
def tag_name
'div'
end

def initialize(*)
super
add_class default_class_name
end

protected

# By default, add a css class named after the ruby class
def default_class_name
self.class.name.demodulize.underscore
end

end
end
14 changes: 6 additions & 8 deletions spec/arbre/unit/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ def build
end

describe Arbre::Component do

let(:assigns) { {} }
let(:helpers) { nil }

let(:component_class){ MockComponent }
let(:component){ component_class.new }
let(:component_class) { MockComponent }
let(:component) { component_class.new }

it "should be a subclass of an html div" do
expect(Arbre::Component.ancestors).to include(Arbre::HTML::Div)
Expand All @@ -28,18 +26,18 @@ def build
expect(component.tag_name).to eq('div')
end

it "should add a class by default" do
expect(component.class_list).to include("mock_component")
it "should not have a class list" do
expect(component.class_list.to_s).to eq("")
expect(component.class_list.empty?).to eq(true)
end

it "should render the object using the builder method name" do
comp = expect(arbre {
mock_component
}.to_s).to eq <<~HTML
<div class="mock_component">
<div>
<h2>Hello World</h2>
</div>
HTML
end

end