From b8eb2b983d842482cc98318e3c7c1157007f545e Mon Sep 17 00:00:00 2001 From: Vito Sartori Date: Sun, 18 Feb 2024 18:20:41 -0300 Subject: [PATCH] feat: Allow symbols to be provided as options --- bin/fetch-icons | 10 ++++++---- lib/lucide-rails.rb | 3 ++- lib/lucide-rails/rails_helper.rb | 4 ++++ .../app/controllers/index_controller.rb | 2 ++ spec/internal/app/views/index/issue14.html.erb | 1 + .../app/views/index/size_option.html.erb | 1 + spec/internal/config/routes.rb | 4 ++++ spec/requests/lucide_spec.rb | 17 +++++++++++++++++ 8 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 spec/internal/app/views/index/issue14.html.erb create mode 100644 spec/internal/app/views/index/size_option.html.erb diff --git a/bin/fetch-icons b/bin/fetch-icons index 98fb411..eafa409 100755 --- a/bin/fetch-icons +++ b/bin/fetch-icons @@ -43,7 +43,7 @@ def system!(cmd, **options) err_writer.close err_reader.close - raise "Process #{cmd} exited with status #{status.exitstatus}: #{stdout}#{stderr}" unless status.success? + raise "Process #{cmd} exited with status #{status.exitstatus}: #{stdout}#{stderr}" unless status.success? stdout end @@ -62,9 +62,11 @@ def clone! tag end File.write "lib/lucide-rails/lucide_version.rb", <<~RUBY - module LucideRails - LUCIDE_VERSION = \"#{tag.strip}\".freeze - end + # frozen_string_literal: true + + module LucideRails + LUCIDE_VERSION = "#{tag.strip}" + end RUBY FileUtils.mv Dir.glob("tmp/lucide/icons/*.svg"), "icons/original" end diff --git a/lib/lucide-rails.rb b/lib/lucide-rails.rb index 7baa09c..e4980b0 100644 --- a/lib/lucide-rails.rb +++ b/lib/lucide-rails.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/gzip" +require "active_support/core_ext/hash/indifferent_access" require_relative "lucide-rails/version" require_relative "lucide-rails/lucide_version" require_relative "lucide-rails/icon_provider" @@ -21,7 +22,7 @@ module LucideRails "stroke-width" => "2", "stroke-linecap" => "round", "stroke-linejoin" => "round" - }.freeze + }.with_indifferent_access.freeze module_function diff --git a/lib/lucide-rails/rails_helper.rb b/lib/lucide-rails/rails_helper.rb index 3a28a8f..2516ed9 100644 --- a/lib/lucide-rails/rails_helper.rb +++ b/lib/lucide-rails/rails_helper.rb @@ -3,6 +3,10 @@ module LucideRails module RailsHelper def lucide_icon(named, **options) + options = options.with_indifferent_access + size = options.delete(:size) + options = options.merge width: size, height: size if size + content_tag(:svg, IconProvider.icon(named).html_safe, LucideRails.default_options.merge(**options)) diff --git a/spec/internal/app/controllers/index_controller.rb b/spec/internal/app/controllers/index_controller.rb index be23590..a2c7b14 100644 --- a/spec/internal/app/controllers/index_controller.rb +++ b/spec/internal/app/controllers/index_controller.rb @@ -2,4 +2,6 @@ class IndexController < ActionController::Base def index; end + def issue14; end + def size_option; end end diff --git a/spec/internal/app/views/index/issue14.html.erb b/spec/internal/app/views/index/issue14.html.erb new file mode 100644 index 0000000..cbce5d7 --- /dev/null +++ b/spec/internal/app/views/index/issue14.html.erb @@ -0,0 +1 @@ +<%= lucide_icon('accessibility', width: '10px', height: '20px') %> diff --git a/spec/internal/app/views/index/size_option.html.erb b/spec/internal/app/views/index/size_option.html.erb new file mode 100644 index 0000000..2a952c0 --- /dev/null +++ b/spec/internal/app/views/index/size_option.html.erb @@ -0,0 +1 @@ +<%= lucide_icon('accessibility', size: '30px') %> diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb index d8f8d71..b920289 100644 --- a/spec/internal/config/routes.rb +++ b/spec/internal/config/routes.rb @@ -2,4 +2,8 @@ Rails.application.routes.draw do root to: "index#index" + + # https://github.com/heyvito/lucide-rails/issues/14 + get "/issue14" => "index#issue14" + get "/size_option" => "index#size_option" end diff --git a/spec/requests/lucide_spec.rb b/spec/requests/lucide_spec.rb index cf0fd0e..701ba09 100644 --- a/spec/requests/lucide_spec.rb +++ b/spec/requests/lucide_spec.rb @@ -7,4 +7,21 @@ expect(response.body).to include("") expect(response.body).to include('custom_attr="yay"') end + + it "allows options to be provided as symbols as well" do + # https://github.com/heyvito/lucide-rails/issues/14 + get "/issue14" + expect(response.body).to include("") + end + + it "allows a single 'size' option to be provided" do + get "/size_option" + expect(response.body).to include("") + end end