Permalink
Browse files

Initial sinatra template & html template

  • Loading branch information...
0 parents commit c319fb36f92ec78c0ef4c6e357ed9987b1135514 @kneath committed Nov 20, 2009
@@ -0,0 +1,2 @@
+.DS_Store
+tmp
@@ -0,0 +1,7 @@
+Copyright (c) 2009 Kyle Neath
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No changes.
@@ -0,0 +1,42 @@
+require "rake/testtask"
+
+desc "Default: run all tests"
+task :default => :test
+
+desc "Run tests"
+task :test => %w(test:units test:acceptance)
+namespace :test do
+ desc "Run unit tests"
+ Rake::TestTask.new(:units) do |t|
+ t.test_files = FileList["test/unit/*_test.rb"]
+ end
+
+ desc "Run acceptance tests"
+ Rake::TestTask.new(:acceptance) do |t|
+ t.test_files = FileList["test/acceptance/*_test.rb"]
+ end
+end
+
+namespace :app do
+ task :setup do
+ require "lib/burndown"
+ Burndown.new(File.dirname(__FILE__) + "/config/config.yml")
+ end
+
+ task :update_milestones => :setup do
+ Burndown::Milestone.sync_with_lighthouse
+ end
+end
+
+task :environment do
+ require "lib/burndown"
+ Burndown.new(File.dirname(__FILE__) + "/config/config.yml")
+end
+
+task :cron => :environment do
+ if Time.now.hour == 01
+ puts "Updating milestones..."
+ Burndown::Milestone.sync_with_lighthouse
+ puts "done."
+ end
+end
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+require 'lib/watchtower'
+
+# Load configuration and initialize Watchtower
+Watchtower.new(File.dirname(__FILE__) + "/config/config.yml")
+
+# You probably don't want to edit anything below
+Watchtower::App.set :environment, ENV["RACK_ENV"] || :production
+Watchtower::App.set :port, 8910
+
+run Watchtower::App
@@ -0,0 +1,14 @@
+# This should be a complete connection string to your database.
+#
+# Examples:
+# * `mysql://user:password@localhost/watchtower`
+# * `postgres://user:password@localhost/watchtower`
+# * `sqlite3:///home/integrity/db/watchtower.sqlite`
+#
+# Note:
+# * The appropriate data_objects adapter must be installed (`do_mysql`, etc)
+# * You must create the `watchtower` database on localhost, of course.
+:database_uri: mysql://root@localhost/watchtower_dev
+
+# Path to the watchtower log file
+:log: /var/log/watchtower.log
@@ -0,0 +1,52 @@
+$:.unshift File.expand_path(File.dirname(__FILE__))
+
+require 'sinatra/base'
+require 'logger'
+
+require 'mongo'
+require 'mustache/sinatra'
+
+require 'watchtower/helpers'
+require 'watchtower/app'
+
+module Watchtower
+ def self.new(config=nil)
+ if config.is_a?(String) && File.file?(config)
+ self.config = YAML.load_file(config)
+ elsif config.is_a?(Hash)
+ self.config = config
+ end
+ end
+
+ def self.default_configuration
+ @defaults ||= { :database_uri => "sqlite3::memory:",
+ :log => STDOUT,
+ :base_uri => "http://localhost:8910",
+ :log_debug_info => false }
+ end
+
+ def self.config
+ @config ||= default_configuration.dup
+ end
+
+ def self.config=(options)
+ @config = default_configuration.merge(options)
+ end
+
+ def self.log(message, &block)
+ logger.info(message, &block)
+ end
+
+ def self.logger
+ @logger ||= Logger.new(config[:log], "daily").tap do |logger|
+ logger.formatter = LogFormatter.new
+ end
+ end
+ private_class_method :logger
+
+ class LogFormatter < Logger::Formatter
+ def call(severity, time, progname, msg)
+ time.strftime("[%H:%M:%S] ") + msg2str(msg) + "\n"
+ end
+ end
+end
@@ -0,0 +1,28 @@
+module Watchtower
+ class App < Sinatra::Default
+ set :root, File.dirname(__FILE__) + "/../.."
+ set :app_file, __FILE__
+ enable :sessions
+
+ include Watchtower
+ include Watchtower::Helpers
+
+ register Mustache::Sinatra
+
+ dir = File.dirname(File.dirname(__FILE__) + "/../../..")
+
+ # Tell mustache where the Views constant lives
+ set :namespace, Watchtower
+
+ # Mustache templates live here
+ set :views, "#{dir}/templates"
+
+ # Tell mustache where the views are
+ set :mustaches, "#{dir}/views"
+
+ get '/' do
+ show :index
+ end
+
+ end
+end
@@ -0,0 +1,21 @@
+module Watchtower
+ module Helpers
+ include Rack::Utils
+ alias :h :escape_html
+
+ def show(template, options = {})
+ @title = options[:title]
+ mustache template
+ end
+
+ def link_to(title, url)
+ %(<a href="#{url}">#{h(title)}</a>)
+ end
+
+ def page_info(options={})
+ @title = options[:title]
+ @breadcrumb = options[:breadcrumb]
+ @page_id = options[:id]
+ end
+ end
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,45 @@
+(function(){
+ window.Watchtower = {}
+
+ var setupClickHandlers = function(){
+ $('ul#nav li').click(function(){
+ Watchtower.App.initBeam($(this).attr('data-service'))
+ })
+ }
+
+ var getBeams = function(){
+ var beams = {}
+ $('ul#nav li').each(function(){
+ var el = $(this)
+ var service = el.attr('data-service')
+ var title = el.attr('data-title')
+ beams[service] = {service: service, title: title, navElement: el}
+ })
+ return beams
+ }
+
+ Watchtower.App = {
+ currentBeam: null,
+
+ init: function(){
+ this.titleElement = $('h1')
+ this.beams = getBeams()
+ setupClickHandlers()
+ this.initBeam('all')
+ },
+
+ initBeam: function(service){
+ if (this.currentBeam == this.beams[service]) return
+
+ if (this.currentBeam) this.currentBeam.navElement.removeClass('selected')
+
+ this.currentBeam = this.beams[service]
+ this.currentBeam.navElement.addClass('selected')
+ }
+ }
+
+})();
+
+$(function(){
+ Watchtower.App.init()
+});

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit c319fb3

Please sign in to comment.