Skip to content

Instantly share code, notes, and snippets.

@minipai
Created March 27, 2011 08:58
Show Gist options
  • Save minipai/889068 to your computer and use it in GitHub Desktop.
Save minipai/889068 to your computer and use it in GitHub Desktop.
My HTML/CSS coding helper
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
@minipai
Copy link
Author

minipai commented Mar 27, 2011

參照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資料夾就好比較方便

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment