Created
March 27, 2011 08:58
-
-
Save minipai/889068 to your computer and use it in GitHub Desktop.
My HTML/CSS coding helper
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
require 'rubygems' | |
require 'sinatra' | |
require 'net/http' | |
get '/' do | |
@stylesheets = Dir.glob("public/css/*.css") | |
@erb = Dir.glob("views/*.erb") | |
@erb.delete('views/layout.erb') | |
@erb.each do |page| | |
page = File.basename(page, '.*') | |
if(page != 'layout') | |
html = Net::HTTP.get(URI.parse("http://localhost:4567/#{page}")) | |
renderFile = File.new('html/' + page + '.html', "w") | |
renderFile.write(html) | |
renderFile.close | |
end | |
end | |
FileUtils.cp_r('public/css', 'html') | |
FileUtils.cp_r('public/images', 'html') | |
set :views, File.dirname(__FILE__) + '/coder' if request.path_info == '/' | |
erb :'index', :layout => false; | |
end | |
get '/:page' do | |
@page = params[:page].to_s | |
set :views, File.dirname(__FILE__) + '/views' | |
erb @page.to_sym | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
參照sinatra的資料夾結構
stylercoder.rb (就是這個gist)
/views
/public
/html
views 裡面的 page.erb 就會對應到 http://localhost:5678/page 然後會自動複製render好的html到 /html裡面
網址連 http://localhost:5678/ 的時候會把public的/css 跟 /image複製到 /html資料夾
這樣子直接給客戶html資料夾就好比較方便