-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add static template generator code extracted from fresh_rails_app
- Loading branch information
1 parent
f3f68b6
commit 01fbdc2
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class StaticController < ApplicationController; end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |