Skip to content

Commit

Permalink
Add static template generator code extracted from fresh_rails_app
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed Aug 30, 2009
1 parent f3f68b6 commit 01fbdc2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class StaticController < ApplicationController; end

38 changes: 38 additions & 0 deletions lib/static_page_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class StaticPageGenerator
class << self
def generate
new.generate
end

attr_writer :settings

def settings
@settings ||= {
:app_host => "localhost:3000"
}
end
end

def generate
templates.each do |template_name|
auth = if settings.key?(:http_basic_auth) && settings[:http_basic_auth].key?(:user) && settings[:http_basic_auth].key?(:password)
" -u #{settings[:http_basic_auth][:user]}:#{settings[:http_basic_auth][:password]} "
else
""
end
sh "curl #{auth} http://#{settings[:app_host]}/static/#{template_name} > #{RAILS_ROOT}/public/#{template_name}.html"
end
end

def templates
@templates ||= Dir.glob("#{RAILS_ROOT}/app/views/static/*").map do |file|
File.basename(file).gsub(".html.erb", "")
end
end

private

def settings
self.class.settings
end
end
8 changes: 8 additions & 0 deletions tasks/static.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + "/../lib/static_page_generator")

namespace :static_templates do
desc "Generate static templates"
task :generate do
StaticPageGenerator.generate
end
end

0 comments on commit 01fbdc2

Please sign in to comment.