Class: EmojiJS::Generate
- Inherits:
-
Object
- Object
- EmojiJS::Generate
- Defined in:
- lib/emoji-js.rb
Instance Method Summary collapse
-
#coffeescript ⇒ Object
takes CoffeeScript from ‘vendor/coffee/emoji.coffee’ and saves the corresponding JS to a variable.
-
#emoji_images ⇒ Object
copy emoji images to image path.
-
#initialize(project_path = Dir.pwd) ⇒ Generate
constructor
A new instance of Generate.
-
#success ⇒ Object
display when successful.
-
#uglify(js) ⇒ Object
takes raw JS and uglifies it.
Constructor Details
#initialize(project_path = Dir.pwd) ⇒ Generate
Returns a new instance of Generate.
8 9 10 11 12 |
# File 'lib/emoji-js.rb', line 8 def initialize(project_path = Dir.pwd) @project_path = project_path @path = File.dirname File.(__FILE__) @vendor_path = "#{@path}/vendor" end |
Instance Method Details
#coffeescript ⇒ Object
takes CoffeeScript from ‘vendor/coffee/emoji.coffee’ and saves the corresponding JS to a variable
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/emoji-js.rb', line 16 def coffeescript @coffee_path = "#{@vendor_path}/coffee" # get image path (we have to do it here because of coffeescript generation) print 'Emoji graphics path: (default: "graphics/") ' @emoji_path = gets.chomp @emoji_path = "/graphics" if @emoji_path.empty? # coffee_grounds = modified coffescript @coffee_grounds = replace_in_file("#{@coffee_path}/emoji.coffee", %q{Emoji.image_path = "/graphics/" # customize to your liking}, "Emoji.image_path = \"#{@emoji_path}\"") @generated_js = CoffeeScript.compile(@coffee_grounds) @ugly_js = uglify @generated_js # get js dir print %q{Your project's JavaScript directory: (default: "js/") } js_dir = gets.chomp js_dir = "js" if js_dir.empty? @orig_js_dir = js_dir js_dir = "#{@project_path}/#{js_dir}" # write emoji.min.js FileUtils.mkdir(js_dir) unless Dir.exists? js_dir FileUtils.cd(js_dir) write_to_file "emoji.min.js", @ugly_js FileUtils.cd("../") end |
#emoji_images ⇒ Object
copy emoji images to image path
50 51 52 53 54 55 56 |
# File 'lib/emoji-js.rb', line 50 def emoji_images @emoji_path = validate_image_path(@emoji_path) FileUtils.mkdir(@emoji_path) unless Dir.exists? @emoji_path @emojis = Dir.glob("#{@vendor_path}/graphics/*").map(&File.method(:realpath)) FileUtils.cp(@emojis, @emoji_path) end |
#success ⇒ Object
display when successful
59 60 61 62 63 64 |
# File 'lib/emoji-js.rb', line 59 def success puts "Emoji.JS successfully added to your project." print "Now add: '".green print "<script src=\"/#{@orig_js_dir}/emoji.min.js\"></script>".blue print "' to the END of your HTML file\n".green end |
#uglify(js) ⇒ Object
takes raw JS and uglifies it
45 46 47 |
# File 'lib/emoji-js.rb', line 45 def uglify(js) Uglifier.compile(js) end |