Skip to content

Commit

Permalink
Run as a sinatra app.
Browse files Browse the repository at this point in the history
Allows for a small amount of dynamism:

* sencha app scripts are loaded automatically from public/app directories
* XTemplates are stored as individual files in templates/
* App.domain is set based on environment
  • Loading branch information
nelstrom committed Mar 24, 2011
1 parent 72dec48 commit a6f11df
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
32 changes: 32 additions & 0 deletions application.rb
@@ -0,0 +1,32 @@
require 'rubygems'
require 'sinatra'

helpers do
def templates
Dir.glob("templates/**").map do |template|
name = File.basename(template, ".html")
content = open(template).read
"<textarea id='#{name}' class='x-hidden-display'>#{content}</textarea>"
end.join("\n")
end

def sencha_app_scripts
sources = ["public/app/routes.js", "public/app/app.js"]

sources << "public/config/#{Sinatra::Application.environment}.js"

%w{models stores views controllers}.each do |layer|
sources += Dir.glob("public/app/#{layer}/**")
end

sources.map do |file|
source = file.sub('public/', '')
"<script src='#{source}' type='text/javascript' charset='utf-8'></script>"
end.join("\n")
end
end

get '/' do
erb :index
end

2 changes: 2 additions & 0 deletions public/config/development.js
@@ -0,0 +1,2 @@
App.environment = "development"
App.domain = "http://localhost:4567";
2 changes: 2 additions & 0 deletions public/config/production.js
@@ -0,0 +1,2 @@
App.environment = "production"
App.domain = "http://all-sorts.org";
12 changes: 12 additions & 0 deletions templates/homecard-list.html
@@ -0,0 +1,12 @@
<ul class="phrases">
<tpl for=".">
<li>
<span class="text">
{article}
<a href="#collectors/{collector_slug}" class="collector">{collector}</a>
of
<a href="#nouns/{noun_slug}" class="noun">{noun}</a>
</span>
</li>
</tpl>
</ul>
34 changes: 34 additions & 0 deletions templates/noun_detail.html
@@ -0,0 +1,34 @@
<ol class="league">
<tpl for=".">
<li>

<p class="noun_phrase">
{article}
<a href="#collectors/{collector_slug}" class="collector">{collector}</a>
of
<a href="#nouns/{noun_slug}" class="noun">{noun}</a>

<span class="seed">
seeded by <a href="http://twitter.com/{seed.user_name}/status/{seed.tweet_id}" class="status_link">{seed.user_name}</a>
</span>

<tpl if="vote_count &amp;gt; 1">
<span class="votes">
#{vote_count} votes
</span>
</tpl>
</p>

<tpl if="vote_count &amp;gt; 1">
<ol>
<tpl for="votes">
<li>
<a href="http://twitter.com/{user_name}/status/{tweet_id}" class="status_link">{user_name}</a>
</li>
</tpl>
</ol>
</tpl>

</li>
</tpl>
</ol>
14 changes: 14 additions & 0 deletions views/index.erb
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>All Sorts</title>
<link href="stylesheets/all-sorts-touch.css" rel="stylesheet" type="text/css" media="screen"/>
<script src="javascripts/sencha-touch.js" type="text/javascript" charset="utf-8"></script>
<%= sencha_app_scripts %>
</head>
<body>

<%= templates %>

</body>
</html>

0 comments on commit a6f11df

Please sign in to comment.