UX: Add login button icon to no_ember page (#7982)

UX: Add login button icon to no_ember page (#7982)

diff --git a/app/views/application/_header.html.erb b/app/views/application/_header.html.erb
index 98440c5..b2d328e 100644
--- a/app/views/application/_header.html.erb
+++ b/app/views/application/_header.html.erb
@@ -17,7 +17,7 @@
               <%- if can_sign_up? %>
                 <a href="<%= path "/signup"%>" class='btn btn-primary btn-small signup-button'><%= I18n.t('sign_up') %></a>
               <%- end %>
-              <a href="<%= path "/login"%>" class='btn btn-primary btn-small login-button'><%= I18n.t('log_in') %></a>
+              <a href="<%= path "/login"%>" class='btn btn-primary btn-small login-button btn-icon-text'><%= SvgSprite.raw_svg('fa-user') %><%= I18n.t('log_in') %></a>
             </div>
           <%- end %>
         </div>
diff --git a/lib/svg_sprite/svg_sprite.rb b/lib/svg_sprite/svg_sprite.rb
index 1d8cd7c..11814d4 100644
--- a/lib/svg_sprite/svg_sprite.rb
+++ b/lib/svg_sprite/svg_sprite.rb
@@ -303,6 +303,19 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
     false
   end
 
+  # For use in no_ember .html.erb layouts
+  def self.raw_svg(name)
+    get_set_cache("raw_svg_#{name}") do
+      symbol = search(name)
+      break "" unless symbol
+      symbol = Nokogiri::XML(symbol).children.first
+      symbol.name = "svg"
+      <<~HTML
+        <svg class="fa d-icon svg-icon svg-node" aria-hidden="true">#{symbol}</svg>
+      HTML
+    end.html_safe
+  end
+
   def self.theme_sprite_variable_name
     THEME_SPRITE_VAR_NAME
   end
diff --git a/spec/components/svg_sprite/svg_sprite_spec.rb b/spec/components/svg_sprite/svg_sprite_spec.rb
index 287e591..c4177cd 100644
--- a/spec/components/svg_sprite/svg_sprite_spec.rb
+++ b/spec/components/svg_sprite/svg_sprite_spec.rb
@@ -29,6 +29,11 @@ describe SvgSprite do
     expect(SvgSprite.search("this-is-not-an-icon")).to eq(false)
   end
 
+  it 'can get a raw SVG for an icon' do
+    expect(SvgSprite.raw_svg("fa-heart")).to match(/svg.*svg/) # SVG inside SVG
+    expect(SvgSprite.raw_svg("this-is-not-an-icon")).to eq("")
+  end
+
   it 'can get a consistent version string' do
     version1 = SvgSprite.version
     version2 = SvgSprite.version

GitHub sha: 7bd54eac

2 Likes