Skip to content

Commit

Permalink
Whitespace cleanup dance
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasottosson committed Mar 23, 2012
1 parent 4d535dd commit 161e337
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions config.yaml.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
s3:
access_key_id:
secret_access_key:
bucket:
access_key_id:
secret_access_key:
bucket:
40 changes: 20 additions & 20 deletions lib/emoji_optimizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Emoji
def self.tmp_dir
@tmp_dir ||= Dir.mktmpdir 'emoji-optimization'
end

class Optimizer

def initialize options = {}
Expand All @@ -15,11 +15,11 @@ def initialize options = {}
@source = Source.new 'public/index.html'
@sprite = Sprite.new @source.emoji_paths, @size, @padding
end

def optimize! &block
puts " ** Preparing for optimization"
puts " ** Preparing for optimization"
prepare

puts " ** Generating emoji sprite image"
if @sprite.generate sprite_path
puts " ** Generating css and updating markup"
Expand All @@ -30,26 +30,26 @@ def optimize! &block

yield

ensure
ensure
puts " ** Cleaning up after optimization"
cleanup
end

private

def prepare
FileUtils.cp 'public/index.html', File.join(Emoji.tmp_dir, 'index.html')
FileUtils.cp 'public/emoji.css', File.join(Emoji.tmp_dir, 'emoji.css')
end

def generate_and_save
update_source_markup

File.open('public/emoji.css', 'a') { |f| f.puts css_rules.join("\n") }
File.open('public/index.html','w') { |f| f.write @source.to_html }
FileUtils.mv sprite_path, "public/graphics/#{digest_name}"
end

def cleanup
FileUtils.mv File.join(Emoji.tmp_dir, 'index.html'), 'public/index.html'
FileUtils.mv File.join(Emoji.tmp_dir, 'emoji.css'), 'public/emoji.css'
Expand All @@ -58,7 +58,7 @@ def cleanup

def css_rules
[].tap do |rules|
rules << %Q{
rules << %Q{
.emoji {
display:inline-block;
width:#{@size}px;
Expand All @@ -81,10 +81,10 @@ def update_source_markup
}
end
end

def css_sprite_mapping index
offset = @sprite.offset index
"#e_#{index+1} { background-position:-#{offset}px 0; }"
"#e_#{index+1} { background-position:-#{offset}px 0; }"
end

def sprite_path
Expand All @@ -96,31 +96,31 @@ def digest_name
end

end

class Source

def initialize file
@file = file
end

def emojis
@emojis ||= doc.css('#content img').find_all { |img| img['src'] =~ /emojis/ }
end

def emoji_paths
@emoji_paths ||= emojis.map { |img| File.join 'public', img['src'] }
end

def create_element *args
doc.create_element *args
end

def to_html
doc.to_html
end

private

def doc
@doc ||= Nokogiri::HTML File.open(@file)
end
Expand All @@ -136,7 +136,7 @@ def initialize files, size, padding
end

def offset index
((@size + @padding * 2) * index) + @padding
((@size + @padding * 2) * index) + @padding
end

def generate path
Expand All @@ -149,7 +149,7 @@ def generate path
system "montage %s %s %s" % [ @files.join(' '), args, path ]
optimize!(path)
end

private

def optimize!(path)
Expand Down
8 changes: 4 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<div id="content">
<h1>Emoji cheat sheet</h1>
<p class="intro">
<a href="http://en.wikipedia.org/wiki/Emoji">Emoji</a> emoticons are supported on
<a href="http://campfirenow.com/" class="product">Campfire</a>,
<a href="http://github.com/" class="product">GitHub</a>,
<a href="http://en.wikipedia.org/wiki/Emoji">Emoji</a> emoticons are supported on
<a href="http://campfirenow.com/" class="product">Campfire</a>,
<a href="http://github.com/" class="product">GitHub</a>,
<a href="http://37signals.com/basecampnext/" class="product">Basecamp Next</a>
and <a href="http://turntable.fm/" class="product">Turntable.fm</a>.<br>
and <a href="http://turntable.fm/" class="product">Turntable.fm</a>.<br>
However some of the emoji codes are not super easy to remember, <em>so here is a little cheat sheet</em>.<br>
<b> Got flash enabled? Click the emoji code and it will be copied to your clipboard.</b> </p>
<h2>People</h2>
Expand Down
8 changes: 4 additions & 4 deletions public/libs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 161e337

Please sign in to comment.