Skip to content

Commit

Permalink
Allow asides to re-order content/aside so that they can stack in reve…
Browse files Browse the repository at this point in the history
…rse order
  • Loading branch information
sfnelson committed Aug 26, 2024
1 parent 1f80fef commit f5dd491
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/models/katalyst/content/aside.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
module Katalyst
module Content
class Aside < Layout
style_attributes do
attribute :reverse, :boolean, default: false
end

def self.permitted_params
super + %i[reverse]
end
end
end
end
5 changes: 5 additions & 0 deletions app/views/katalyst/content/asides/_aside.html+form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<%= form.check_box :visible %>
</div>

<div class="field">
<%= form.label :reverse %>
<%= form.check_box :reverse %>
</div>

<%= form.submit "Done" %>
<%= link_to "Discard", :back %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/katalyst/content/asides/_aside.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% if aside.children.any? %>
<% items = aside.children.select(&:visible?) %>
<% last = items.pop %>
<div role="aside-container">
<div role="aside-container" <%= "class=reverse" if aside.reverse %>>
<div>
<%= render_content_items items %>
</div>
Expand Down
9 changes: 7 additions & 2 deletions spec/models/katalyst/content/aside_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
require_relative "item_examples"

RSpec.describe Katalyst::Content::Aside do
subject(:aside) { build(:katalyst_content_section, container: page) }
subject(:aside) { build(:katalyst_content_aside, container: page) }

let(:page) { create(:page) }

it_behaves_like "a item" do
let(:item) { aside }
end

it "can round trip style attributes" do
aside = create(:katalyst_content_aside, container: page, reverse: true)
expect(aside.reload).to have_attributes(reverse: true)
end

describe "#to_plain_text" do
it { is_expected.to have_attributes(to_plain_text: aside.heading) }

context "when heading is hidden" do
subject(:aside) { build(:katalyst_content_section, heading_style: "none", container: page) }
subject(:aside) { build(:katalyst_content_aside, heading_style: "none", container: page) }

it { is_expected.to have_attributes(to_plain_text: nil) }
end
Expand Down

0 comments on commit f5dd491

Please sign in to comment.