Skip to content

Commit

Permalink
added Rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
gaarf committed Aug 1, 2010
1 parent 28690a0 commit 37310e6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
build/
69 changes: 69 additions & 0 deletions Rakefile
@@ -0,0 +1,69 @@
#!/usr/bin/env ruby
task :default => :generate_html
directory "build"

class LineCommands
require 'yui/compressor' # http://github.com/sstephenson/ruby-yui-compressor

def compress(line, path, mode=nil)
puts " - COMPRESS #{path}"
mode ||= extract_suffix(path)
compressor = (mode == :css) ? YUI::CssCompressor.new : YUI::JavaScriptCompressor.new
file = File.new(path)
compressor.compress(file.read)
end

def inline(line,a)
return line unless path = line[/(link rel="stylesheet"|script).*(href|src)="([^"]+)"/i,3]
case extract_suffix(path)
when :js then "<script type=\"text/javascript\">\n#{compress(nil,path,:js)}\n</script>"
when :css then "<style type=\"text/css\" media=\"#{line[/media="([^"]+)"/i,1]||'screen'}\">\n#{compress(nil,path,:css)}\n</style>"
else line
end
end

def delete(line,a)
''
end

def eval(line,code)
Kernel::eval(code)
end

private
def extract_suffix(path)
(path[/\.(css|js)$/i,1]||:unknown).to_sym
end
end

desc "generate stand-alone page.html"
task :generate_html => ["build"] do

puts "loading index.html..."
indexhtml = File.new('index.html')
n = 1
output = ''
processor = LineCommands.new
while (line = indexhtml.gets)
line.rstrip!
if m = line[/###\s*RAKE\s+(.+)\s*###/i,1]
args = m.strip.split
command = args.shift.downcase.to_sym
puts "\nfound command \"#{command}\" on line ##{n}"
begin
line = processor.send(command,line,args.join(' '))
rescue Exception => e
puts "! error running \"#{command}\" !"
puts e.inspect
end
end
output << line+"\n"
n += 1
end

puts "\nwriting to build/page.html..."
File.open("build/page.html", 'w') {|f| f << output}
puts "all done!"
end


16 changes: 10 additions & 6 deletions index.html
Expand Up @@ -9,16 +9,16 @@
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/reset-fonts/reset-fonts.css" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lobster" />

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="style.css" /> <!-- ### RAKE inline ### -->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="lib/jqDnR-touch/jqdnr.js"></script>
<script type="text/javascript" src="http://platform.twitter.com/anywhere.js?id=6OBf6rxxfj8QrWs5T3tHw&amp;v=1"></script>

<script type="text/javascript" src="grfModuleSet.js"></script> <!-- core page code -->
<script type="text/javascript" src="modules.js"></script> <!-- defines MODULES -->
<script type="text/javascript" src="lib/jqDnR-touch/jqdnr.js"></script> <!-- ### RAKE inline ### -->
<script type="text/javascript" src="grfModuleSet.js"></script> <!-- ### RAKE inline ### core page code -->
<script type="text/javascript" src="modules.js"></script> <!-- ### RAKE delete ### -->

<script>
<script type="text/javascript">
jQuery(document).ready(function($){

if (!window.console) {
Expand All @@ -28,7 +28,11 @@
for (var i = 0; i < names.length; ++i) { window.console[names[i]] = function() {}; }
}

$('#modules').grfModuleSet(MODULES, 1);
var BUILD = 1; // ### RAKE delete ###
// ### RAKE eval "var BUILD = #{Time.now.to_i};" ###
// ### RAKE compress modules.js ###

$('#modules').grfModuleSet(MODULES, BUILD);

if(twttr) {
twttr.anywhere(function(T) {
Expand Down
2 changes: 1 addition & 1 deletion lib/jqDnR-touch
Submodule jqDnR-touch updated 1 files
+1 −1 README.md
2 changes: 1 addition & 1 deletion modules.js
@@ -1,4 +1,4 @@
MODULES = [
var MODULES = [

{
sKey: 'welcome',
Expand Down

0 comments on commit 37310e6

Please sign in to comment.