font_awesome_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE.md +26 -0
  5. data/README.md +69 -0
  6. data/Rakefile +6 -0
  7. data/app/assets/stylesheets/_font-awesome.scss +2 -0
  8. data/app/assets/stylesheets/font-awesome/_font.scss +13 -0
  9. data/app/assets/stylesheets/font-awesome/_icons.scss +210 -0
  10. data/app/assets/stylesheets/font-awesome/_mixins.scss +58 -0
  11. data/app/assets/stylesheets/font-awesome/_styles.scss +53 -0
  12. data/font_awesome_rails.gemspec +25 -0
  13. data/lib/font_awesome/font.rb +52 -0
  14. data/lib/font_awesome/hex_code.rb +39 -0
  15. data/lib/font_awesome/icon.rb +80 -0
  16. data/lib/font_awesome/nokogiri.rb +17 -0
  17. data/lib/font_awesome/sass_extensions/functions.rb +26 -0
  18. data/lib/font_awesome/sass_extensions.rb +6 -0
  19. data/lib/font_awesome.rb +10 -0
  20. data/lib/font_awesome_rails/engine.rb +4 -0
  21. data/lib/font_awesome_rails/version.rb +3 -0
  22. data/lib/font_awesome_rails.rb +10 -0
  23. data/spec/font_awesome/font_spec.rb +103 -0
  24. data/spec/font_awesome/hex_code_spec.rb +66 -0
  25. data/spec/font_awesome/icon_spec.rb +92 -0
  26. data/spec/font_awesome/sass_extensions/functions_spec.rb +69 -0
  27. data/spec/spec_helper.rb +14 -0
  28. data/spec/tasks/update_classic_sass_task_spec.rb +33 -0
  29. data/spec/tasks/update_hex_codes_task_spec.rb +44 -0
  30. data/spec/tasks/update_metrics_task_spec.rb +34 -0
  31. data/spec/tasks/update_sass_task_spec.rb +20 -0
  32. data/tasks/gem_dir.rb +12 -0
  33. data/tasks/spec.rake +3 -0
  34. data/tasks/task.rb +5 -0
  35. data/tasks/update/classic.rake +27 -0
  36. data/tasks/update/font.rake +13 -0
  37. data/tasks/update/font_awesome.rake +20 -0
  38. data/tasks/update/hex_codes.rake +9 -0
  39. data/tasks/update/metrics.rake +8 -0
  40. data/tasks/update/metrics.rb +62 -0
  41. data/tasks/update/sass.rake +6 -0
  42. data/tasks/update/update_classic_sass_task.rb +21 -0
  43. data/tasks/update/update_hex_codes_task.rb +34 -0
  44. data/tasks/update/update_metrics_task.rb +25 -0
  45. data/tasks/update/update_sass_task.rb +20 -0
  46. data/tasks/update.rake +8 -0
  47. data/vendor/assets/font/fontawesome-webfont.eot +0 -0
  48. data/vendor/assets/font/fontawesome-webfont.svg +255 -0
  49. data/vendor/assets/font/fontawesome-webfont.ttf +0 -0
  50. data/vendor/assets/font/fontawesome-webfont.woff +0 -0
  51. data/vendor/assets/stylesheets/font-awesome/_classic.scss +292 -0
  52. data/vendor/assets/stylesheets/font-awesome/ie7.css +645 -0
  53. metadata +225 -0
@@ -0,0 +1,62 @@
1
+ require "font_awesome"
2
+ require "RMagick"
3
+
4
+ module Metrics
5
+ extend self
6
+
7
+ def ascent
8
+ Ascent.new.actual_height
9
+ end
10
+
11
+ def descent
12
+ -Descent.new.actual_height
13
+ end
14
+
15
+ class Image < FontAwesome::Icon
16
+ def initialize
17
+ super(nil)
18
+ end
19
+
20
+ def actual_height
21
+ to_image.trim.rows
22
+ end
23
+
24
+ def to_image
25
+ Magick::Image.from_blob(to_svg){self.format = "svg"}.first
26
+ end
27
+
28
+ protected
29
+
30
+ def build_svg(xml)
31
+ xml.svg svg_attributes do
32
+ FontAwesome::Icon.all.each do |icon|
33
+ xml.path icon.path_attributes
34
+ end
35
+ end
36
+ end
37
+
38
+ def svg_attributes
39
+ super.merge(width:"2048px", height:"2048px")
40
+ end
41
+
42
+ def offset_x
43
+ 0
44
+ end
45
+ end
46
+
47
+ class Ascent < Image
48
+ protected
49
+
50
+ def offset_y
51
+ 2048
52
+ end
53
+ end
54
+
55
+ class Descent < Image
56
+ protected
57
+
58
+ def offset_y
59
+ 0
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,6 @@
1
+ namespace :update do
2
+ task :sass do
3
+ require_relative "update_sass_task"
4
+ UpdateSassTask.new.run
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../task"
2
+
3
+ class UpdateClassicSassTask < Task
4
+ def run
5
+ puts "* Updating #{path}"
6
+
7
+ open_file(path, "w") {|file| file.write styles }
8
+ end
9
+
10
+ def styles
11
+ contents.match(%r{/\* Font Awesome styles.*}m) {|matched| matched.to_s }
12
+ end
13
+
14
+ def contents
15
+ open_file("Font-Awesome/sass/font-awesome.scss") {|file| file.read }
16
+ end
17
+
18
+ def path
19
+ "vendor/assets/stylesheets/font-awesome/_classic.scss"
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "../task"
2
+
3
+ class UpdateHexCodesTask < Task
4
+ def run
5
+ puts "* Updating #{hex_code_class_path}"
6
+
7
+ source = updated_hex_code_class
8
+ open_file(hex_code_class_path, "w") do |file|
9
+ file.write source
10
+ end
11
+ end
12
+
13
+ def hex_codes
14
+ css.scan(/\.icon-([-a-z]+):before.+content: "\\([a-f\d]+)";/).inject({}) do |result, (name, hex_code)|
15
+ result.merge name => hex_code
16
+ end
17
+ end
18
+
19
+ def updated_hex_code_class
20
+ hex_code_class.sub(/HEX_CODES = {[^}]*}/, "HEX_CODES = #{hex_codes}")
21
+ end
22
+
23
+ def hex_code_class
24
+ open_file(hex_code_class_path)
25
+ end
26
+
27
+ def hex_code_class_path
28
+ "lib/font_awesome/hex_code.rb"
29
+ end
30
+
31
+ def css
32
+ open_file("Font-Awesome/css/font-awesome.css")
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../task"
2
+ require_relative "metrics"
3
+
4
+ class UpdateMetricsTask < Task
5
+ def run
6
+ puts "* Updating #{font_class_path}"
7
+
8
+ source = updated_font_class
9
+ open_file(font_class_path, "w") do |file|
10
+ file.write source
11
+ end
12
+ end
13
+
14
+ def updated_font_class
15
+ font_class.sub(/ASCENT = \d+/, "ASCENT = #{Metrics.ascent}").sub(/DESCENT = -\d+/, "DESCENT = #{Metrics.descent}")
16
+ end
17
+
18
+ def font_class
19
+ open_file(font_class_path)
20
+ end
21
+
22
+ def font_class_path
23
+ "lib/font_awesome/font.rb"
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../task"
2
+ require "font_awesome/icon"
3
+
4
+ class UpdateSassTask < Task
5
+ def run
6
+ puts "* Updating #{path}"
7
+
8
+ open_file(path, "w") {|file| file.write contents }
9
+ end
10
+
11
+ def contents
12
+ FontAwesome::Icon.all.map do |icon|
13
+ "%icon-#{icon.name} { content: '#{icon.hex_code.to_css}'; }\n"
14
+ end.join
15
+ end
16
+
17
+ def path
18
+ "app/assets/stylesheets/font-awesome/_icons.scss"
19
+ end
20
+ end
data/tasks/update.rake ADDED
@@ -0,0 +1,8 @@
1
+ require_relative "gem_dir"
2
+
3
+ desc "Update Font Awesome and generate code"
4
+ task :update => "update:all"
5
+
6
+ namespace :update do
7
+ task :all => [:font_awesome, :font, :hex_codes, :metrics, :sass, :classic]
8
+ end