Skip to content

Commit

Permalink
Add links to tiles (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi authored Oct 20, 2023
1 parent 836b8ea commit 92db8dd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ class TilesCell < BaseCell
def translated_title(item_number = nil)
return translated_attribute(model.settings.title) if item_number.blank?

translated_attribute(model.settings.send("title_#{item_number}"))
if translated_url(item_number).blank?
translated_attribute(model.settings.send("title_#{item_number}"))
else
link_to translated_attribute(model.settings.send("title_#{item_number}")), translated_url(item_number)
end
end

def translated_body(item_number)
translated_attribute(model.settings.send("body_#{item_number}"))
end

def translated_url(item_number)
translated_attribute(model.settings.send("link_url_#{item_number}"))
end

def background_image(item_number)
model.images_container.attached_uploader("background_image_#{item_number}".to_sym).path(variant: :landscape)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div class="large-3 p-xs">
<%= settings_fields.translated :text_field, :"title_#{item_number}", label: t(".title_n", item_number: item_number) %>
<%= settings_fields.translated :text_area, :"body_#{item_number}", rows: 3, label: t(".body_n", item_number: item_number) %>
<%= settings_fields.translated :text_field, :"link_url_#{item_number}", label: t(".link_url_n", item_number: item_number) %>
</div>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
max-width: 20em;
background: $alternative-color-1;
padding: $gap;

h2 {
a {
color: $header-color;
}
}
}

&-heading {
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ en:
tiles_settings_form:
background_image_n: 'Background image for item #%{item_number}'
body_n: 'Body #%{item_number}'
link_url_n: 'Link URL for item #%{item_number}'
title: Title
title_n: 'Title #%{item_number}'
upcoming_meetings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
1.upto(4).map do |item_number|
settings.attribute :"title_#{item_number}", type: :text, translated: true
settings.attribute :"body_#{item_number}", type: :text, translated: true
settings.attribute :"link_url_#{item_number}", type: :text, translated: true
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/shared/system_homepage_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
within ".tile-body" do
expect(page).to have_i18n_content(tiles_block.settings.send(:"title_#{item_number}"))
expect(page).to have_i18n_content(tiles_block.settings.send(:"body_#{item_number}"))
expect(page).to have_link(tiles_block.settings.send(:"body_#{item_number}")[I18n.locale]) if tiles_block.settings.send(:"link_url_#{item_number}").present?
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/system/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@

describe "tiles block" do
it_behaves_like "render tiles block elements"

context "with link" do
before do
settings = tiles_block.settings
settings.link_url_1 = Decidim::Faker::Localized.literal(Faker::Internet.url)
tiles_block.settings = settings
tiles_block.save
end

it_behaves_like "render tiles block elements"
end
end

describe "latest_blog_posts block" do
Expand Down

0 comments on commit 92db8dd

Please sign in to comment.