Skip to content

Commit

Permalink
Merge pull request #6 from avonderluft/version106
Browse files Browse the repository at this point in the history
Version106
  • Loading branch information
avonderluft committed Sep 6, 2023
2 parents 72628b0 + 6bb3df4 commit 06768c2
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.0.6 - 9/5/2023

- Fixed [cms:siblings Nav tag](https://github.com/avonderluft/occams/wiki/Content-Tags#siblings) to handle edge case when page(s) are excluded by the `exclude` parameter
- Added [cms:children Nav tag](https://github.com/avonderluft/occams/wiki/Content-Tags#children) to render unordered list of links for children of current page

## v1.0.5 - 8/31/2023

- All tests now green on Rails 6.1 and 7.0, each tested with rubies 2.7.8, 3.1.4 and 3.2.2.
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ group :development, :test do
gem 'capybara', '~> 3.39.0'
gem 'image_processing', '>= 1.2'
gem 'kaminari', '~> 1.2', '>= 1.2.2'
gem 'puma', '~> 3.12.2'
gem 'rubocop', '~> 0.55.0', require: false
gem 'selenium-webdriver', '~> 4.9.0'
gem 'sqlite3', '~> 1.4.2'
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# ocCaM'S

Prefer Simplicity

## Raison d'etre

ocCaM'S is a revival of [ComfortableMexicanSofa](https://github.com/comfy/comfortable-mexican-sofa), with all due thanks and acknowledgements to [Oleg Khabarov](https://github.com/GBH), et al. 'Comfy' was the simplest and cleanest Rails-based CMS that I had used. Its last commit was in 2020, and I simply did not want to see it die on the vine as [RadiantCMS](https://github.com/radiant/radiant) did some years ago.
[![Gem Version](https://img.shields.io/gem/v/occams.svg?style=flat)](http://rubygems.org/gems/occams)
[![Gem Downloads](https://img.shields.io/gem/dt/occams.svg?style=flat)](http://rubygems.org/gems/occams)

```
____ __ __ _ ____
Expand All @@ -15,6 +12,13 @@ ocCaM'S is a revival of [ComfortableMexicanSofa](https://github.com/comfy/comfor
```

Prefer Simplicity.

## Raison d'etre

ocCaM'S is a revival of [ComfortableMexicanSofa](https://github.com/comfy/comfortable-mexican-sofa), with all due thanks and acknowledgements to [Oleg Khabarov](https://github.com/GBH), et al. 'Comfy' was the simplest and cleanest Rails-based CMS that I had used. Its last commit was in 2020, and I simply did not want to see it die on the vine as [RadiantCMS](https://github.com/radiant/radiant) did some years ago.


## The name

ocCaM'S, pronounced "AH-kums" is a nod to [Occam's Razor](https://en.wikipedia.org/wiki/Occam%27s_razor) - for this Rails-based Content Management System endeavors to follow the principle that the preferred solution is that which is simplest and built with the smallest possible set of components.
Expand All @@ -36,7 +40,7 @@ Referring to the [ComfortableMexicanSofa](https://github.com/comfy/comfortable-m
## Dependencies

* File attachments are handled by [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage). Make sure that you can run appropriate migrations by running: `rails active_storage:install` and then `rake db:migrate`
* Image resizing is done on Rails 7 or greater, with[ImageMagick](http://www.imagemagick.org/script/download.php), so make sure it's installed
* Image resizing is done with[ImageMagick](http://www.imagemagick.org/script/download.php), so make sure it's installed
* Pagination is handled by [kaminari](https://github.com/amatsuda/kaminari) or [will_paginate](https://github.com/mislav/will_paginate). Please add one of those to your Gemfile.

## Compatibility
Expand Down
3 changes: 2 additions & 1 deletion TODOS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ToDos

- set up CI
- set up Buildkite CI and add build badge to README
- add duplicate page function in admin UI
- add admin content search to list layouts, pages and snippets - see https://blog.robertsj.com/search/
- add application console for testing
- add feature to resize file_link'd images
1 change: 1 addition & 0 deletions lib/occams/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ module Occams::Content

require_relative 'content/tags/audio'
require_relative 'content/tags/breadcrumbs'
require_relative 'content/tags/children'
require_relative 'content/tags/siblings'
50 changes: 50 additions & 0 deletions lib/occams/content/tags/children.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# Nav Tag for unordered list of links to the children of the current page
# {{ cms:children }}
# {{ cms:children style: "font-weight: bold", exclude: "404-page, search-page" }}
# To customize your children style, add a 'children' id to your CSS, e.g
# #children {
# color: #006633;
# font-size: 90%;
# margin-bottom: 4px;
# font-style: italic;
# }
# and/or pass in style overrides with the 'style' parameter, as above
#
# To exclude children, list their slugs with the 'exclude' parameter
# as comma-delimited string, e.g. as above - exclude: "404-page, search-page"

class Occams::Content::Tag::Children < Occams::Content::Tag
attr_reader :list, :style, :locals

def initialize(context:, params: [], source: nil)
super
@locals = params.extract_options!
@style = ''
@style = "<style>#children {#{@locals['style']}}</style>" if @locals['style']
@exclude = []
@exclude = @locals['exclude'].split(',') if @locals['exclude']
@list = ''
# ActiveRecord_Associations_CollectionProxy
page_children = context.children.order(:position).to_ary
page_children.delete_if { |child| @exclude.include? child.slug }
return unless page_children.any?

@list = '<ul id="children">'
page_children.each do |c|
next if Rails.env == 'production' && !c.is_published

@list += "<li><a href=#{c.url(relative: true)}>#{c.label}</a></li>"
end
@list += '</ul>'
end

def content
format("#{@style}#{@list}")
end
end

Occams::Content::Renderer.register_tag(
:children, Occams::Content::Tag::Children
)
4 changes: 1 addition & 3 deletions lib/occams/content/tags/siblings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
# To customize your siblings style, add a 'siblings' id to your CSS, e.g
# #siblings {
# color: #006633;
# font-family: Verdana, Arial, Helvetica, sans-serif;
# font-size: 95%;
# margin-top: 12px;
# margin-bottom: 4px;
# font-style: italic;
# }
# and/or pass in style overrides with the 'style' parameter (see above)
Expand All @@ -33,11 +31,11 @@ def initialize(context:, params: [], source: nil)

prevp = false
sibs = context.self_and_siblings.sort_by(&:position)
sibs.delete_if { |sib| @exclude.include? sib.slug }
page_idx = sibs.index(context)
sibs.each do |sib|
sib_idx = sibs.index(sib)
next if sibs.index(sib) == page_idx
next if @exclude.include? sib.slug
next if Rails.env == 'production' && !sib.is_published

if sib_idx == page_idx - 1
Expand Down
2 changes: 1 addition & 1 deletion lib/occams/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Occams
VERSION = '1.0.5'
VERSION = '1.0.6'
end
1 change: 0 additions & 1 deletion test/gemfiles/6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ group :development, :test do
gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw]
gem 'capybara', '~> 2.17.0'
gem 'kaminari', '~> 1.1.1'
gem 'puma', '~> 3.12.2'
gem 'rubocop', '~> 0.55.0', require: false
gem 'selenium-webdriver', '~> 3.9.0'
gem 'sqlite3', '~> 1.4.2'
Expand Down
1 change: 0 additions & 1 deletion test/gemfiles/7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ group :development, :test do
gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw]
gem 'capybara', '~> 3.39.0'
gem 'kaminari', '~> 1.2', '>= 1.2.2'
gem 'puma', '~> 3.12.2'
gem 'rubocop', '~> 0.55.0', require: false
gem 'selenium-webdriver', '~> 4.9.0'
gem 'sqlite3', '~> 1.4.2'
Expand Down
1 change: 1 addition & 0 deletions test/lib/content/renderer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestBlockTag < Occams::Content::Block
'template' => Occams::Content::Tag::Template,
'audio' => Occams::Content::Tag::Audio,
'breadcrumbs' => Occams::Content::Tag::Breadcrumbs,
'children' => Occams::Content::Tag::Children,
'siblings' => Occams::Content::Tag::Siblings
}.freeze

Expand Down
61 changes: 61 additions & 0 deletions test/lib/content/tags/children_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require_relative '../../../test_helper'

class ContentTagsChildrenTest < ActiveSupport::TestCase
setup do
@site = occams_cms_sites(:default)
@layout = occams_cms_layouts(:default)
@page = occams_cms_pages(:default)
@parent = @site.pages.create!(layout: @layout, parent: @page, label: 'Parent', slug: 'parent')
@child1 = @site.pages.create!(layout: @layout, parent: @parent, label: 'Child1', slug: 'child1')
@child2 = @site.pages.create!(layout: @layout, parent: @parent, label: 'Child2', slug: 'child2')
@child3 = @site.pages.create!(layout: @layout, parent: @parent, label: 'Child3', slug: 'child3')
@child4 = @site.pages.create!(layout: @layout, parent: @parent, label: 'Child4', slug: 'child4')
end

def test_init
tag = Occams::Content::Tag::Children.new(
context: @parent,
params: []
)
assert_equal ({}), tag.locals
end

def test_init_with_style
tag = Occams::Content::Tag::Children.new(
context: @parent,
params: [{ 'style' => 'font-weight: bold' }]
)
assert_equal '<style>#children {font-weight: bold}</style>', tag.style
end

def test_render
tag = Occams::Content::Tag::Children.new(
context: @parent,
params: [{ 'style' => 'font-weight: bold' }]
)
html = "<style>#children {font-weight: bold}</style><ul id=\"children\">\
<li><a href=/parent/child1>Child1</a></li><li><a href=/parent/child2>Child2</a></li>\
<li><a href=/parent/child3>Child3</a></li><li><a href=/parent/child4>Child4</a></li></ul>"
assert_equal html, tag.render
end

def test_render_with_exclusions
tag = Occams::Content::Tag::Children.new(
context: @parent,
params: [{ 'exclude' => 'child2,child3' }]
)
html = "<ul id=\"children\"><li><a href=/parent/child1>Child1</a></li>\
<li><a href=/parent/child4>Child4</a></li></ul>"
assert_equal html, tag.render
end

def test_render_with_no_kids
tag = Occams::Content::Tag::Children.new(
context: @child4,
params: []
)
assert_equal '', tag.render
end
end
11 changes: 11 additions & 0 deletions test/lib/content/tags/siblings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ContentTagsSiblingsTest < ActiveSupport::TestCase
@second = @site.pages.create!(layout: @layout, parent: @page, label: 'Second', slug: 'second')
@third = @site.pages.create!(layout: @layout, parent: @page, label: 'Third', slug: 'third')
@fourth = @site.pages.create!(layout: @layout, parent: @page, label: 'Fourth', slug: 'fourth')
@fifth = @site.pages.create!(layout: @layout, parent: @page, label: 'Fifth', slug: 'fifth')
end

def test_init
Expand Down Expand Up @@ -39,4 +40,14 @@ def test_render
&bull; <em>Next</em>&nbsp;&raquo; <a href=/fourth>Fourth</a></div>"
assert_equal html, tag.render
end

def test_render_with_exclusions
tag = Occams::Content::Tag::Siblings.new(
context: @third,
params: [{ 'exclude' => 'second,fourth' }]
)
html = "<div id=\"siblings\"><a href=/first>First</a> &laquo;&nbsp;<em>Previous</em> \
&bull; <em>Next</em>&nbsp;&raquo; <a href=/fifth>Fifth</a></div>"
assert_equal html, tag.render
end
end

0 comments on commit 06768c2

Please sign in to comment.