Permalink
Browse files

add initial helpers and gems

  • Loading branch information...
1 parent 7daeccb commit 8465fc925e350c94cb43f4937b1fe202c3724637 David Radcliffe committed Dec 15, 2011
Showing with 85 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. +12 −5 Gemfile
  3. +3 −3 Rakefile
  4. +61 −0 lib/simple_site.rb
  5. +8 −0 lib/simple_site/haml_helper.rb
View
@@ -46,3 +46,4 @@ pkg
# For rubinius:
#*.rbc
+Gemfile.lock
View
17 Gemfile
@@ -1,10 +1,17 @@
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.
-# Include everything needed to run rake, tests, features, etc.
+gem 'rake'
+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
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
View
@@ -17,9 +17,9 @@ Jeweler::Tasks.new do |gem|
gem.name = "simple_site"
gem.homepage = "http://github.com/dwradcliffe/simple_site"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "david@etchdev.com"
+ gem.summary = %Q{Simple website builder.}
+ gem.description = %Q{Helps build simple websites using haml and sass. Compresses your js. Deploys to AWS S3.}
+ gem.email = "radcliffe.david@gmail.com"
gem.authors = ["David Radcliffe"]
# dependencies defined in Gemfile
end
View
@@ -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
@@ -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.