-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add components for Article #24
Changes from 1 commit
8fdffa9
d1c587d
795b144
d8c8d71
23d2aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,7 @@ RSpec/ContextWording: | |
Prefixes: | ||
- when | ||
- given | ||
|
||
Lint/MissingSuper: | ||
Exclude: | ||
- 'app/components/**/*' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ApplicationComponent < ViewComponent::Base | ||
def initialize(tag: nil, classes: nil, **options) | ||
@tag = tag | ||
@classes = classes | ||
@options = options | ||
end | ||
|
||
def call | ||
content_tag(@tag, content, class: @classes, **@options) if @tag | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="post-preview"> | ||
<%= link_to article do %> | ||
<h2 class="post-title"><%= article.title %></h2> | ||
<h3 class="post-subtitle"><%= truncate(article.content.to_plain_text, length: 100) %></h3> | ||
<% end %> | ||
|
||
<%= render PostingDetails::Component.new(name: 'Author', time: article.created_at) %> | ||
</div> | ||
<!-- Divider--> | ||
<hr class="my-4" /> | ||
<!-- Pager--> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Articles | ||
module ListItems | ||
class Component < ApplicationComponent | ||
attr_reader :article | ||
|
||
with_collection_parameter :article | ||
|
||
def initialize(article:) | ||
@article = article | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||
# frozen_string_literal: true | ||||
|
||||
module Base | ||||
module Button | ||||
class Component < ApplicationComponent | ||||
|
||||
attr_reader :type, :link | ||||
|
||||
BASE_CLASSES = %w[btn].freeze | ||||
|
||||
PRIMARY_CLASSES = %w[btn-primary].freeze | ||||
SECONDARY_CLASSES = %w[btn-secondary].freeze | ||||
SUCCESS_CLASSES = %w[btn-success].freeze | ||||
DANGER_CLASSES = %w[btn-danger].freeze | ||||
LINK_CLASSES = %w[btn-link].freeze | ||||
|
||||
BUTTON_TYPE_MAPPING = { | ||||
primary: PRIMARY_CLASSES, | ||||
secondary: SECONDARY_CLASSES, | ||||
success: SUCCESS_CLASSES, | ||||
danger: DANGER_CLASSES, | ||||
link: LINK_CLASSES | ||||
}.freeze | ||||
|
||||
def initialize(type: :primary, link: '#', **options) | ||||
@options = options | ||||
|
||||
@options[:tag] ||= :a | ||||
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering a few days ago how to have a clean solution that accepts both That way is nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. Will do that, |
||||
@options[:href] = link | ||||
@options[:classes] = classes(type) | ||||
end | ||||
|
||||
def call | ||||
render ApplicationComponent.new(**@options).with_content(content) | ||||
end | ||||
|
||||
private | ||||
|
||||
def classes(type) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
(BASE_CLASSES + BUTTON_TYPE_MAPPING[type]).join(' ') | ||||
end | ||||
end | ||||
end | ||||
end |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Header | ||
class Component < ApplicationComponent | ||
attr_reader :image, :heading, :subheading | ||
|
||
def initialize(image:, heading:, subheading:) | ||
@image = image | ||
@heading = heading | ||
@subheading = subheading | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p class="post-meta">Posted by <a href="#"><%= name %></a> on <%= post_time(time) %></p> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module PostingDetails | ||
class Component < ApplicationComponent | ||
attr_reader :time, :name | ||
def initialize(name:, time:) | ||
@name = name | ||
@time = time | ||
end | ||
|
||
delegate :post_time, to: :helpers | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class Article < ApplicationRecord | ||
has_many :comments | ||
|
||
has_one_attached :avatar | ||
|
||
validates :title, presence: true | ||
has_rich_text :content | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.