Skip to content

Commit

Permalink
add initial helpers and gems
Browse files Browse the repository at this point in the history
  • Loading branch information
David Radcliffe committed Dec 15, 2011
1 parent 7daeccb commit 8465fc9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -46,3 +46,4 @@ pkg


# For rubinius: # For rubinius:
#*.rbc #*.rbc
Gemfile.lock
17 changes: 12 additions & 5 deletions Gemfile
@@ -1,10 +1,17 @@
source "http://rubygems.org" source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"


# Add dependencies to develop your gem here. gem 'rake'
# Include everything needed to run rake, tests, features, etc. gem 'haml'
gem 'sass'
gem 'uglifier'
gem 'guard'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
gem 'growl'
gem 'guard-shell'
gem 'aws-s3'

group :development do group :development do
gem "shoulda", ">= 0" gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0" gem "bundler", "~> 1.0.0"
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -17,9 +17,9 @@ Jeweler::Tasks.new do |gem|
gem.name = "simple_site" gem.name = "simple_site"
gem.homepage = "http://github.com/dwradcliffe/simple_site" gem.homepage = "http://github.com/dwradcliffe/simple_site"
gem.license = "MIT" gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem} gem.summary = %Q{Simple website builder.}
gem.description = %Q{TODO: longer description of your gem} gem.description = %Q{Helps build simple websites using haml and sass. Compresses your js. Deploys to AWS S3.}
gem.email = "david@etchdev.com" gem.email = "radcliffe.david@gmail.com"
gem.authors = ["David Radcliffe"] gem.authors = ["David Radcliffe"]
# dependencies defined in Gemfile # dependencies defined in Gemfile
end end
Expand Down
61 changes: 61 additions & 0 deletions lib/simple_site.rb
@@ -0,0 +1,61 @@
require 'aws/s3'
require 'uglifier'

class SimpleSite

def initialize(options = {})
@options = options
@options[:js_files] ||= Dir['_js/*.js']
@options[:buckets] ||= []
end

def generate_html
system "haml -r simple_site/haml_helper.rb _src/index.haml public/index.html"
puts "Regenerated site!"
end

def generate_css
system "sass _sass/style.sass public/css/style.css"
puts "Regenerated css!"
end

def generate_js
system 'mkdir -p _tmp; touch _tmp/js.js; :> _tmp/js.js'
@options[:js_files].each do |f|
system "cat _js/#{f} >> _tmp/js.js"
end
File.open('public/js/script.js', 'w') {|f| f.write(Uglifier.compile(File.read('_tmp/js.js'))) }
system 'rm _tmp/js.js'
puts "Regenerated js!"
end

def deploy!
Dir.chdir('public')
Dir['**/*'].select { |f| File.file?(f) }.each do |file|
deploy file
end
end

def deploy_file!
Dir.chdir('public')
ENV['FILES'].select { |f| File.file?(f) }.each do |file|
deploy file
end
end


private
def deploy(file)
age = 7*24*60*60
options = {
:access => :public_read,
:cache_control => "max-age=#{age}",
:expires => age.from_now.httpdate
}
puts " --> #{file}"
@options[:buckets].each do |bucket|
AWS::S3::S3Object.store(file, open(file), bucket, options)
end
end

end
8 changes: 8 additions & 0 deletions lib/simple_site/haml_helper.rb
@@ -0,0 +1,8 @@
def render_file(filename)
contents = File.read(filename)
Haml::Engine.new(contents).render
end

def partial partial_name
render_file "_src/_#{partial_name}.haml"
end

0 comments on commit 8465fc9

Please sign in to comment.