Skip to content

Commit

Permalink
Update to gem version 1.1.1
Browse files Browse the repository at this point in the history
- bump to Rails 7.1.3.3
- bugfix: uploaded files index page was blank
- create cms:image tag, simplifying from cms:file_link
- add 'title' attribute to images
- update and optimize test suite
- update gems
  • Loading branch information
avonderluft committed May 19, 2024
1 parent 15027d1 commit 1d96893
Show file tree
Hide file tree
Showing 29 changed files with 216 additions and 107 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require:
# - rubocop-rails
# - rubocop-minitest

AllCops:
TargetRubyVersion: 2.7
NewCops: enable
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v.1.1.1 dd mm 2024

- bump to Rails 7.1.3.3
- bugfix: uploaded files index page was blank
- create cms:image tag, simplifying from cms:file_link
- add 'title' attribute to images
- update and optimize test suite

## v.1.1.0 13 May 2024

- Rails 7.1 compatibility, all tests passing
Expand Down
27 changes: 13 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,34 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec

gem 'rails', '~> 7.1.2'
gem 'rails', '~> 7.1.3'

group :development, :test do
gem 'autoprefixer-rails', '~> 8.1.0'
gem 'autoprefixer-rails', '~> 10.4.16.0'
gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.2'
gem 'image_processing', '>= 1.12.0'
gem 'sqlite3', '~> 1.6.7'
# gem 'mysql2', '~> 0.5'
# gem 'pg', '~> 1.5.4'
end

group :development do
gem 'listen', '~> 3.8.0'
gem 'listen', '~> 3.9.0'
gem 'web-console', '~> 4.2'
end

group :test do
gem 'brakeman', '~> 5.4.1'
gem 'brakeman', '~> 6.1.2'
gem 'bundler-audit', '~> 0.9.1'
gem 'capybara', '~> 3.39.0'
gem 'coveralls_reborn', '~> 0.28.0', require: false
gem 'cuprite', '~> 0.14.3'
gem 'diffy', '~> 3.4.2'
gem 'cuprite', '>= 0.15'
gem 'equivalent-xml', '~> 0.6.0'
gem 'minitest', '~> 5.20.0'
gem 'minitest-reporters', '~> 1.6.1'
gem 'mocha', '~> 2.1.0', require: false
gem 'puma', '~> 6.4.0'
gem 'minitest', '>= 5.23.0'
gem 'minitest-reporters', '>= 1.6.1'
gem 'mocha', '>= 2.3.0', require: false
gem 'rails-controller-testing', '~> 1.0.5'
gem 'rubocop', '~> 1.56.0', require: false
gem 'simplecov', '~> 0.22.0', require: false
gem 'rubocop', '~> 1.63.0', require: false
gem 'rubocop-minitest'
gem 'rubocop-rails'
gem 'simplecov', '~> 0.22.0', require: false
end
5 changes: 2 additions & 3 deletions TODOS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ToDos

- 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
- diagnose and correct failure of ImageMagick params in file_link and image cms tags
- lint for rubocop-rails and rubocop-minitest
8 changes: 5 additions & 3 deletions app/controllers/concerns/occams/paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

module Occams::Paginate
def occams_paginate(scope, per_page: 50)
return unless defined?(Kaminari)

scope.page(params[:page]).per(per_page)
if defined?(Kaminari)
scope.page(params[:page]).per(per_page)
else
scope
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/occams/admin/cms/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def check_for_layouts

def build_page
@page = @site.pages.new(page_params)
@page.parent ||= (@site.pages.find_by_id(params[:parent_id]) || @site.pages.root)
@page.layout ||= (@page.parent&.layout || @site.layouts.first)
@page.parent ||= @site.pages.find_by_id(params[:parent_id]) || @site.pages.root
@page.layout ||= @page.parent&.layout || @site.layouts.first
end

def load_page
Expand Down
7 changes: 5 additions & 2 deletions app/helpers/occams/admin/cms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def cms_page_file_link_tag(fragment_id:, attachment:, multiple:)
# @param [Occams::Cms::File] file
# @return [String] {{ cms:file_link #{file.id}, ... }}
def cms_file_link_tag(file)
as = ', as: image' if file.attachment.image?
"{{ cms:file_link #{file.id}#{as} }}"
if file.attachment.image?
"{{ cms:image #{file.label} }}"
else
"{{ cms:file_link #{file.id} }}"
end
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/occams/cms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def cms_site_detect
def occams_paginate(collection)
return unless collection

return unless defined?(Kaminari)

paginate collection, theme: 'occams'
paginate collection, theme: 'occams' if defined?(Kaminari)
end
end
end
1 change: 1 addition & 0 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Define an application-wide content security policy.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
Expand Down
1 change: 1 addition & 0 deletions config/initializers/new_framework_defaults_7_1.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.
#
# This file eases your Rails 7.1 framework defaults upgrade.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/permissions_policy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Define an application-wide HTTP permissions policy. For further
Expand Down
31 changes: 13 additions & 18 deletions gemfiles/6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,26 @@ gemspec path: '../'
gem 'rails', '~> 6.1.0'

group :development, :test do
gem 'autoprefixer-rails', '~> 8.1.0'
gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.2'
gem 'autoprefixer-rails', '~> 10.4.16.0'
gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.12.0'
gem 'sqlite3', '~> 1.6.7'
end

group :development do
gem 'listen', '~> 3.8.0'
gem 'web-console', '~> 4.2'
# gem 'mysql2', '~> 0.5'
# gem 'pg', '~> 1.5.4'
end

group :test do
gem 'brakeman', '~> 5.4.1'
gem 'brakeman', '~> 6.1.2'
gem 'bundler-audit', '~> 0.9.1'
gem 'capybara', '~> 3.39.0'
gem 'coveralls_reborn', '~> 0.28.0', require: false
gem 'cuprite', '~> 0.14.3'
gem 'diffy', '~> 3.4.2'
gem 'cuprite', '>= 0.15'
gem 'equivalent-xml', '~> 0.6.0'
gem 'minitest', '~> 5.20.0'
gem 'minitest-reporters', '~> 1.6.1'
gem 'mocha', '~> 2.1.0', require: false
gem 'puma', '~> 6.4.0'
gem 'minitest', '>= 5.23.0'
gem 'minitest-reporters', '>= 1.6.1'
gem 'mocha', '>= 2.3.0', require: false
gem 'rails-controller-testing', '~> 1.0.5'
gem 'rubocop', '~> 1.56.0', require: false
gem 'selenium-webdriver', '~> 4.9.0'
gem 'rubocop', '~> 1.63.0', require: false
gem 'rubocop-minitest'
gem 'rubocop-rails'
gem 'simplecov', '~> 0.22.0', require: false
end
30 changes: 12 additions & 18 deletions gemfiles/7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ gemspec path: '../'
gem 'rails', '~> 7.0.0'

group :development, :test do
gem 'autoprefixer-rails', '~> 8.1.0'
gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.2'
gem 'autoprefixer-rails', '~> 10.4.16.0'
gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.12.0'
gem 'sqlite3', '~> 1.6.7'
end

group :development do
gem 'listen', '~> 3.8.0'
gem 'web-console', '~> 4.2'
end

group :test do
gem 'brakeman', '~> 5.4.1'
gem 'brakeman', '~> 6.1.2'
gem 'bundler-audit', '~> 0.9.1'
gem 'capybara', '~> 3.39.0'
gem 'coveralls_reborn', '~> 0.28.0', require: false
gem 'cuprite', '~> 0.14.3'
gem 'diffy', '~> 3.4.2'
gem 'cuprite', '>= 0.15'
gem 'equivalent-xml', '~> 0.6.0'
gem 'minitest', '~> 5.20.0'
gem 'minitest-reporters', '~> 1.6.1'
gem 'mocha', '~> 2.1.0', require: false
gem 'puma', '~> 6.4.0'
gem 'minitest', '>= 5.23.0'
gem 'minitest-reporters', '>= 1.6.1'
gem 'mocha', '>= 2.3.0', require: false
gem 'rails-controller-testing', '~> 1.0.5'
gem 'rubocop', '~> 1.56.0', require: false
gem 'simplecov', '~> 0.22.0', require: false
gem 'rubocop', '~> 1.63.0', require: false
gem 'rubocop-minitest'
gem 'rubocop-rails'
gem 'simplecov', '~> 0.22.0', require: false
end
30 changes: 12 additions & 18 deletions gemfiles/7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ gemspec path: '../'
gem 'rails', '~> 7.1.0', '>= 7.1.1'

group :development, :test do
gem 'autoprefixer-rails', '~> 8.1.0'
gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.2'
gem 'autoprefixer-rails', '~> 10.4.16.0'
gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw]
gem 'image_processing', '>= 1.12.0'
gem 'sqlite3', '~> 1.6.7'
end

group :development do
gem 'listen', '~> 3.8.0'
gem 'web-console', '~> 4.2'
end

group :test do
gem 'brakeman', '~> 5.4.1'
gem 'brakeman', '~> 6.1.2'
gem 'bundler-audit', '~> 0.9.1'
gem 'capybara', '~> 3.39.0'
gem 'coveralls_reborn', '~> 0.28.0', require: false
gem 'cuprite', '~> 0.14.3'
gem 'diffy', '~> 3.4.2'
gem 'cuprite', '>= 0.15'
gem 'equivalent-xml', '~> 0.6.0'
gem 'minitest', '~> 5.20.0'
gem 'minitest-reporters', '~> 1.6.1'
gem 'mocha', '~> 2.1.0', require: false
gem 'puma', '~> 6.4.0'
gem 'minitest', '>= 5.23.0'
gem 'minitest-reporters', '>= 1.6.1'
gem 'mocha', '>= 2.3.0', require: false
gem 'rails-controller-testing', '~> 1.0.5'
gem 'rubocop', '~> 1.56.0', require: false
gem 'simplecov', '~> 0.22.0', require: false
gem 'rubocop', '~> 1.63.0', require: false
gem 'rubocop-minitest'
gem 'rubocop-rails'
gem 'simplecov', '~> 0.22.0', require: false
end
1 change: 1 addition & 0 deletions lib/occams/content/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Occams::Content::Tags
require_relative 'tags/snippet'
require_relative 'tags/asset'
require_relative 'tags/file_link'
require_relative 'tags/image'
require_relative 'tags/page_file_link'
require_relative 'tags/helper'
require_relative 'tags/partial'
Expand Down
22 changes: 9 additions & 13 deletions lib/occams/content/tags/file_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
# {{cms:file_link id, as: image}}
#
# `as` - url (default) | link | image - how file gets rendered out
# `label` - attach label attribute to link or image tag
# `resize` - imagemagic option. For example: "100x50>"
# `gravity` - imagemagic option. For example: "center"
# `crop` - imagemagic option. For example: "100x50+0+0"
# `class` - any html classes that you want on the result link or image tag. For example "class1 class2"
#
# - variant_attrs are not functional, perhaps due to some change in ImageMagick
# - Simply use a class in your CSS / SASS to style your image display
# `label` - attach label attribute to link or image tag
# `resize` - imagemagick option. For example: "100x50>"
# `gravity` - imagemagick option. For example: "center"
# `crop` - imagemagick option. For example: "100x50+0+0"
#
class Occams::Content::Tags::FileLink < Occams::Content::Tag
include Occams::Content::Tags::Mixins::FileContent

# @return [String] A {Occams::Cms::Site#files} ID.
attr_reader :identifier

# @type ["url", "link", "image"]
attr_reader :as

# @type [{String => String}]
attr_reader :variant_attrs
attr_reader :identifier, :as, :variant_attrs

def initialize(context:, params: [], source: nil)
super
Expand All @@ -32,7 +28,7 @@ def initialize(context:, params: [], source: nil)
@identifier = params[0]
@as = options['as'] || 'url'
@class = options['class']
@variant_attrs = options.slice('resize', 'gravity', 'crop')
@variant_attrs = options.slice('resize', 'gravity', 'crop') # broken for ImageMagick

return if @identifier.present?

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

require_relative 'mixins/file_content'

# This is like the the file_link tag, but specifically for images
# Identify the image by its label {{ cms:image label }}
#
# `class` - any html classes that you want on the image tag. For example "class1 class2"
#
# - variant_attrs are not functional, perhaps due to some change in ImageMagick
# - Simply use a class in your CSS / SASS to style your image display
# `label` - attach label attribute to link or image tag
# `resize` - imagemagick option. For example: "100x50>"
# `gravity` - imagemagick option. For example: "center"
# `crop` - imagemagick option. For example: "100x50+0+0"

class Occams::Content::Tags::Image < Occams::Content::Tag
include Occams::Content::Tags::Mixins::FileContent

attr_reader :identifier, :as, :variant_attrs

def initialize(context:, params: [], source: nil)
super

options = params.extract_options!
@identifier = params[0]
@as = 'image'
@class = options['class']
@variant_attrs = options.slice('resize', 'gravity', 'crop') # broken for ImageMagick

return if @identifier.present?

raise Error, 'Missing identifier label for image tag'
end

# @return [Occams::Cms::File]
def file_record
@file_record ||= context.site.files.detect { |f| f.label == identifier }
end

# @return [ActiveStorage::Blob]
def file
file_record&.attachment
end

# @return [String]
def label
return '' if file_record.nil?

file_record.label.presence || file.filename.to_s
end
end

Occams::Content::Renderer.register_tag(
:image, Occams::Content::Tags::Image
)
Loading

0 comments on commit 1d96893

Please sign in to comment.