Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions app/helpers/rails_icons/icon_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_icons (1.4.0)
rails_icons (1.5.0)
nokogiri (~> 1.16, >= 1.16.4)
rails (>= 7.0)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_icons (1.4.0)
rails_icons (1.5.0)
nokogiri (~> 1.16, >= 1.16.4)
rails (>= 7.0)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_icons (1.4.0)
rails_icons (1.5.0)
nokogiri (~> 1.16, >= 1.16.4)
rails (>= 7.0)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
rails_icons (1.4.0)
rails_icons (1.5.0)
nokogiri (~> 1.16, >= 1.16.4)
rails (>= 7.0)

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_main.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ GIT
PATH
remote: ..
specs:
rails_icons (1.4.0)
rails_icons (1.5.0)
nokogiri (~> 1.16, >= 1.16.4)
rails (>= 7.0)

Expand Down
2 changes: 1 addition & 1 deletion lib/rails_icons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_relative "rails_icons/configuration"
require_relative "rails_icons/engine"
require_relative "rails_icons/errors"
require_relative "rails_icons/railtie"
# require_relative "rails_icons/railtie"
require_relative "rails_icons/icon"

module RailsIcons
Expand Down
8 changes: 8 additions & 0 deletions lib/rails_icons/engine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# frozen_string_literal: true

require "rails_icons/helpers/icon_helper"

module RailsIcons
class Engine < ::Rails::Engine
isolate_namespace RailsIcons

initializer "rails_icons.helpers" do
ActiveSupport.on_load(:action_view) do
include RailsIcons::Helpers::IconHelper
end
end
end
end
27 changes: 27 additions & 0 deletions lib/rails_icons/helpers/icon_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module RailsIcons
module Helpers
module IconHelper
def icon(name, library: RailsIcons.configuration.default_library, from: library, variant: nil, **arguments)
RailsIcons::Icon.new(
name: name,
library: from || library,
variant: variant,
arguments: arguments
).svg
end

def encoded_icon(name, library: RailsIcons.configuration.default_library, from: library, variant: nil, **arguments)
svg_content = RailsIcons::Icon.new(
name: name,
library: from || library,
variant: variant,
arguments: arguments
).svg

"data:image/svg+xml;base64,#{Base64.strict_encode64(svg_content)}"
end
end
end
end
11 changes: 0 additions & 11 deletions lib/rails_icons/railtie.rb

This file was deleted.

1 change: 1 addition & 0 deletions test/dummy/tmp/local_secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
009546a8fedf9834cd724cd7e230efba87ccd0d0820891a165e19a76b42352ef0b5d498c22acd2c1293762034c3e540b156f981384520bb32e10c3b9f09d43f1
13 changes: 13 additions & 0 deletions test/rails_icons/icon_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "test_helper"

class IconHelperTest < ActiveSupport::TestCase
test "icon helper constant is defined" do
assert defined?(RailsIcons::Helpers::IconHelper)
end

test "icon helper can be included in classes" do
test_class = Class.new { include RailsIcons::Helpers::IconHelper }

assert test_class.new.respond_to?(:icon)
end
end
7 changes: 7 additions & 0 deletions test/rails_icons/icon_helper_view_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class IconHelperViewTest < ActionView::TestCase
test "icon helper is automatically available in views" do
assert ActionView::Base.instance_methods.include?(:icon), "icon method should be included in ActionView::Base"
end
end
Loading