Skip to content

Commit

Permalink
Refactored multi-site support to not switch the public directory at r…
Browse files Browse the repository at this point in the history
…untime. This was causing issues with pages served from the cache not having access to image resources.
  • Loading branch information
reidab committed Mar 11, 2009
1 parent 1f7389b commit 1451ca0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 17 deletions.
7 changes: 3 additions & 4 deletions README.markdown
Expand Up @@ -4,10 +4,9 @@ TweetScope makes it easy to create themed single-page displays of twitter search

## Quick Setup ##

1. Copy the default site folder to create your new site.
2. Edit general_config.yml to set the your site as the defaut.
3. Edit your site's config.yml file to set your site's title, tagline, query, and the number of results to display.
4. Customize the appearance of your site by editing the css file (public/style.css) and the view template (views/index.haml). Files added to the public directory, such as images, will be available at the root of your site's domain. The view template is written using [haml](http://haml.hamptoncatlin.com/).
1. Create a new site with rake site:create
2. Edit your site's config.yml file (sites/sitename/config.yml) to set your site's title, tagline, query, and the number of results to display.
4. Customize the appearance of your site by editing the css file (public/sitename/style.css) and the view template (sites/sitename/index.haml). The view template is written using [haml](http://haml.hamptoncatlin.com/).
5. Test things out by running `ruby tweetscope.rb` and visiting [http://localhost:4567](http://localhost:4567) in your browser.

## Configuration ##
Expand Down
34 changes: 34 additions & 0 deletions Rakefile
@@ -0,0 +1,34 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require 'rake'

namespace :site do

desc "creates a new site"
task :create, [:site_name] do |t, args|
print "Site Name: "
if site_name = args.site_name
puts site_name
else
site_name = STDIN.readline.chomp
end

site_dir = "sites/#{site_name}"
public_dir = "public/#{site_name}"

raise "Site already exists" if File.exists?(site_dir)

puts "Creating directories: #{site_dir}, #{public_dir}"
FileUtils.mkdir_p([site_dir, public_dir])

puts "Copying site files."
File.open("#{site_dir}/config.yml",'w') {|f| f.write( open('lib/site_skel/config.yml').read.gsub("%%_SITENAME_%%",site_name) ) }

File.open("#{site_dir}/index.haml",'w') {|f| f.write( open('lib/site_skel/index.haml').read.gsub("%%_SITENAME_%%",site_name) ) }

puts "Copying public files."
FileUtils.cp('lib/site_skel/public/style.css',public_dir)
end

end
4 changes: 2 additions & 2 deletions global_config.yml
@@ -1,2 +1,2 @@
default_site: default
cache_max_age: 300
cache_max_age: 300
# default_site: site_name
1 change: 1 addition & 0 deletions lib/config_reader.rb
Expand Up @@ -6,6 +6,7 @@ def self.read
next if site == '.' || site == '..' || !File.directory?("sites/#{site}")
config[site] = read_config_file("sites/#{site}/config.yml")
end
raise "No sites were found. Create a site using 'rake site:create' before running TweetScope." if config.keys.size == 1

config['_domains'] = build_domain_map(config)

Expand Down
6 changes: 6 additions & 0 deletions lib/site_skel/config.yml
@@ -0,0 +1,6 @@
# TweetScope Configuration

title: %%_SITENAME_%%
tagline: A New TweetScope Site
query: "%%_SITENAME_%%"
count: 20
Expand Up @@ -2,7 +2,7 @@
%html
%head
%title== #{@site['title']}: #{@site['tagline']}
%link{ :rel => 'stylesheet', :type => 'text/css', :href => '/style.css' }
%link{ :rel => 'stylesheet', :type => 'text/css', :href => '%%_SITENAME_%%/style.css' }
%body
#header
%h1.page_title= @site['title']
Expand Down
File renamed without changes.
Empty file added public/.holder
Empty file.
6 changes: 0 additions & 6 deletions sites/default/config.yml

This file was deleted.

6 changes: 2 additions & 4 deletions tweetscope.rb
Expand Up @@ -9,12 +9,10 @@
config = ConfigReader.read

get '/:site?/?' do |site|
site ||= config['_domains'][request.env['SERVER_NAME']]
site ||= config['_global']['default_site']
site ||= config['_domains'][request.env['SERVER_NAME']] || config['_global']['default_site'] || config.keys.reject{|k| k[0]==95 }.first

raise Sinatra::NotFound unless config.has_key?(site)
set :public, File.dirname(__FILE__) + "/sites/#{site}/public"
set :views, File.dirname(__FILE__) + "/sites/#{site}/views"
set :views, File.dirname(__FILE__) + "/sites/#{site}"
@site = config[site]

querystring = ''
Expand Down

0 comments on commit 1451ca0

Please sign in to comment.