font-awesome-propshaft 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ module FontAwesomePropshaft
2
+ module Rails
3
+ module IconHelper
4
+ # Creates an icon tag given an icon name and possible icon
5
+ # modifiers.
6
+ #
7
+ # Examples
8
+ #
9
+ # fa_icon "camera-retro"
10
+ # # => <i class="fa fa-camera-retro"></i>
11
+ #
12
+ # fa_icon "camera-retro", text: "Take a photo"
13
+ # # => <i class="fa fa-camera-retro"></i> Take a photo
14
+ # fa_icon "chevron-right", text: "Get started", right: true
15
+ # # => Get started <i class="fa fa-chevron-right"></i>
16
+ #
17
+ # fa_icon "camera-retro 2x"
18
+ # # => <i class="fa fa-camera-retro fa-2x"></i>
19
+ # fa_icon ["camera-retro", "4x"]
20
+ # # => <i class="fa fa-camera-retro fa-4x"></i>
21
+ # fa_icon "spinner spin lg"
22
+ # # => <i class="fa fa-spinner fa-spin fa-lg">
23
+ #
24
+ # fa_icon "quote-left 4x", class: "pull-left"
25
+ # # => <i class="fa fa-quote-left fa-4x pull-left"></i>
26
+ #
27
+ # fa_icon "user", data: { id: 123 }
28
+ # # => <i class="fa fa-user" data-id="123"></i>
29
+ #
30
+ # content_tag(:li, fa_icon("check li", text: "Bulleted list item"))
31
+ # # => <li><i class="fa fa-check fa-li"></i> Bulleted list item</li>
32
+ def fa_icon(names = "flag", original_options = {})
33
+ options = original_options.deep_dup
34
+ classes = ["fa"]
35
+ classes.concat Private.icon_names(names)
36
+ classes.concat Array(options.delete(:class))
37
+ text = options.delete(:text)
38
+ right_icon = options.delete(:right)
39
+ icon = content_tag(:i, nil, options.merge(:class => classes))
40
+ Private.icon_join(icon, text, right_icon)
41
+ end
42
+
43
+ # Creates an stack set of icon tags given a base icon name, a main icon
44
+ # name, and possible icon modifiers.
45
+ #
46
+ # Examples
47
+ #
48
+ # fa_stacked_icon "twitter", base: "square-o"
49
+ # # => <span class="fa-stack">
50
+ # # => <i class="fa fa-square-o fa-stack-2x"></i>
51
+ # # => <i class="fa fa-twitter fa-stack-1x"></i>
52
+ # # => </span>
53
+ #
54
+ # fa_stacked_icon "terminal inverse", base: "square", class: "pull-right", text: "Hi!"
55
+ # # => <span class="fa-stack pull-right">
56
+ # # => <i class="fa fa-square fa-stack-2x"></i>
57
+ # # => <i class="fa fa-terminal fa-inverse fa-stack-1x"></i>
58
+ # # => </span> Hi!
59
+ #
60
+ # fa_stacked_icon "camera", base: "ban-circle", reverse: true
61
+ # # => <span class="fa-stack">
62
+ # # => <i class="fa fa-camera fa-stack-1x"></i>
63
+ # # => <i class="fa fa-ban-circle fa-stack-2x"></i>
64
+ # # => </span>
65
+ def fa_stacked_icon(names = "flag", original_options = {})
66
+ options = original_options.deep_dup
67
+ classes = Private.icon_names("stack").concat(Array(options.delete(:class)))
68
+ base_names = Private.array_value(options.delete(:base) || "square-o").push("stack-2x")
69
+ names = Private.array_value(names).push("stack-1x")
70
+ base = fa_icon(base_names, options.delete(:base_options) || {})
71
+ icon = fa_icon(names, options.delete(:icon_options) || {})
72
+ icons = [base, icon]
73
+ icons.reverse! if options.delete(:reverse)
74
+ text = options.delete(:text)
75
+ right_icon = options.delete(:right)
76
+ stacked_icon = content_tag(:span, safe_join(icons), options.merge(:class => classes))
77
+ Private.icon_join(stacked_icon, text, right_icon)
78
+ end
79
+
80
+ module Private
81
+ extend ActionView::Helpers::OutputSafetyHelper
82
+
83
+ def self.icon_join(icon, text, reverse_order = false)
84
+ return icon if text.blank?
85
+ elements = [icon, ERB::Util.html_escape(text)]
86
+ elements.reverse! if reverse_order
87
+ safe_join(elements, " ")
88
+ end
89
+
90
+ def self.icon_names(names = [])
91
+ array_value(names).map { |n| "fa-#{n}" }
92
+ end
93
+
94
+ def self.array_value(value = [])
95
+ value.is_a?(Array) ? value : value.to_s.split(/\s+/)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,6 @@
1
+ module FontAwesomePropshaft
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module FontAwesomePropshaft
2
+ module Rails
3
+ FA_VERSION = "1.0.1"
4
+ VERSION = "1.0.1"
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ require "font-awesome-propshaft/version"
2
+ require "font-awesome-propshaft/engine" if defined?(::Rails)
@@ -0,0 +1 @@
1
+ @import font-awesome-propshaft
@@ -0,0 +1 @@
1
+ @import "font-awesome-propshaft";
@@ -0,0 +1,2 @@
1
+ class PagesController < ActionController::Base
2
+ end
@@ -0,0 +1,3 @@
1
+ <%= fa_icon "flag" %>
2
+
3
+ <%= fa_stacked_icon "twitter", :base => "check-empty" %>
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "rails/all"
4
+ require "propshaft"
5
+
6
+ Bundler.require(:default, :development)
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ config.encoding = "utf-8"
11
+
12
+ # replacement for environments/*.rb
13
+ config.active_support.deprecation = :stderr
14
+ config.eager_load = false
15
+ config.active_support.test_order = :random rescue nil
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ #
8
+ # avoid deprecation warnings if building against older versions of Rails
9
+
10
+ # secret_token migrated to secret_key_base in Rails 4
11
+ SKB_VERSION = Gem::Version.new('4.0.0')
12
+
13
+ # Get the current Rails version.
14
+ RAILS_VERSION = Rails.respond_to?(:version) ? Gem::Version.new(Rails.version) : Gem::Version.new('3.22')
15
+
16
+
@@ -0,0 +1,3 @@
1
+ Dummy::Application.routes.draw do
2
+ get "/icons", :to => "pages#icons"
3
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application