Skip to content

Commit

Permalink
feat: Allow symbols to be provided as options
Browse files Browse the repository at this point in the history
  • Loading branch information
heyvito committed Feb 18, 2024
1 parent 55ad415 commit b8eb2b9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 5 deletions.
10 changes: 6 additions & 4 deletions bin/fetch-icons
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/lucide-rails.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -21,7 +22,7 @@ module LucideRails
"stroke-width" => "2",
"stroke-linecap" => "round",
"stroke-linejoin" => "round"
}.freeze
}.with_indifferent_access.freeze

module_function

Expand Down
4 changes: 4 additions & 0 deletions lib/lucide-rails/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions spec/internal/app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

class IndexController < ActionController::Base
def index; end
def issue14; end
def size_option; end
end
1 change: 1 addition & 0 deletions spec/internal/app/views/index/issue14.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= lucide_icon('accessibility', width: '10px', height: '20px') %>
1 change: 1 addition & 0 deletions spec/internal/app/views/index/size_option.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= lucide_icon('accessibility', size: '30px') %>
4 changes: 4 additions & 0 deletions spec/internal/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions spec/requests/lucide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@
expect(response.body).to include("</svg>")
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("<svg")
expect(response.body).to include('width="10px"')
expect(response.body).to include('height="20px"')
expect(response.body).to include("</svg>")
end

it "allows a single 'size' option to be provided" do
get "/size_option"
expect(response.body).to include("<svg")
expect(response.body).to include('width="30px"')
expect(response.body).to include('height="30px"')
expect(response.body).to include("</svg>")
end
end

0 comments on commit b8eb2b9

Please sign in to comment.