Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit d3a11341701d5f7fff03e5c8a78e537985d223c7 @brianjlandau brianjlandau committed Oct 13, 2009
Showing 948 changed files with 76,386 additions and 0 deletions.
@@ -0,0 +1,7 @@
+.rsync_cache
+.DS_Store
+coverage/*
+log/*.log
+tmp/*
+tmp/**/*
+config/settings.yml
@@ -0,0 +1,17 @@
+RAKE_ENV = ENV['RAKE_ENV'] || 'development'
+
+desc 'Default task: run all tests'
+task :default => [:test]
+
+task :test do
+ exec "thor monk:test"
+end
+
+task :environment do
+ $:.push(File.dirname(__FILE__))
+ require 'init'
+end
+
+Dir['tasks/**/*.rake'].each do |rakefile|
+ load rakefile
+end
@@ -0,0 +1,60 @@
+class Monk < Thor
+ include Thor::Actions
+
+ desc "test", "Run all tests"
+ def test
+ verify_config(:test)
+
+ $:.unshift File.join(File.dirname(__FILE__), "test")
+
+ Dir['test/**/*_test.rb'].each do |file|
+ load file unless file =~ /^-/
+ end
+ end
+
+ desc "stories", "Run user stories."
+ method_option :pdf, :type => :boolean
+ def stories
+ $:.unshift(Dir.pwd, "test")
+
+ ARGV << "-r"
+ ARGV << (options[:pdf] ? "stories-pdf" : "stories")
+ ARGV.delete("--pdf")
+
+ Dir["test/stories/*_test.rb"].each do |file|
+ load file
+ end
+ end
+
+ desc "start ENV", "Start Monk in the supplied environment"
+ def start(env = ENV["RACK_ENV"] || "development")
+ verify_config(env)
+
+ exec "env RACK_ENV=#{env} ruby init.rb"
+ end
+
+ desc "copy_example EXAMPLE, TARGET", "Copies an example file to its destination"
+ def copy_example(example, target = target_file_for(example))
+ File.exists?(target) ? return : say_status(:missing, target)
+ File.exists?(example) ? copy_file(example, target) : say_status(:missing, example)
+ end
+
+private
+
+ def self.source_root
+ File.dirname(__FILE__)
+ end
+
+ def target_file_for(example_file)
+ example_file.sub(".example", "")
+ end
+
+ def verify_config(env)
+ verify "config/settings.example.yml"
+ end
+
+ def verify(example)
+ copy_example(example) unless File.exists?(target_file_for(example))
+ end
+
+end
@@ -0,0 +1,34 @@
+class Main
+ module Helpers
+ module AppHelper
+
+ def html_escape(s)
+ s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
+ end
+ alias h html_escape
+
+ def input(type, name, value = nil, options = {})
+ label = options[:label] || name.titlecase
+ html_id = options[:name] || name
+ <<-HTML
+ <p>
+ <label for="#{html_id}">#{label}</label>
+ <input type="#{type.to_s}" id="#{html_id}" name="#{name}" value="#{h(value.to_s)}" />
+ </p>
+HTML
+ end
+
+ def text_area(name, value = nil, options = {})
+ label = options[:label] || name.titlecase
+ html_id = options[:name] || name
+ <<-HTML
+ <p>
+ <label for="#{html_id}">#{label}</label>
+ <textarea name="#{name}" id="#{html_id}">#{h(value.to_s)}</textarea>
+ </p>
+HTML
+ end
+
+ end
+ end
+end
@@ -0,0 +1,12 @@
+class Main
+ helpers do
+ # Your helpers go here. You can also create another file in app/helpers with the same format.
+ # All helpers defined here will be available across all the application.
+ #
+ # @example A helper method for date formatting.
+ #
+ # def format_date(date, format = "%d/%m/%Y")
+ # date.strftime(format)
+ # end
+ end
+end
@@ -0,0 +1,27 @@
+class Main
+ module Helpers
+ module SitesHelper
+
+ def name_input(value = nil)
+ input(:text, 'site[name]', value, :id => 'site-name', :label => 'Site Name')
+ end
+
+ def url_input(value = nil)
+ input(:text, 'site[url]', value, :id => 'site-url', :label => 'Site URL')
+ end
+
+ def text_match_input(value = nil)
+ text_area('site[match_text]', value, :id => 'site-match_text', :label => 'Text to Match')
+ end
+
+ def threshold_input(value = nil)
+ input(:text, 'site[threshold]', value, :id => 'site-threshold', :label => '# of Failures')
+ end
+
+ def email_input(value = nil)
+ input(:text, 'site[email]', value, :id => 'site-email', :label => 'Email Address')
+ end
+
+ end
+ end
+end
No changes.
@@ -0,0 +1,40 @@
+require 'uri'
+
+class Site < Ohm::Model
+ module Regex
+ include URI::REGEXP::PATTERN
+ # A general email regular expression. It allows top level domains (TLD) to be from 2 - 4 in length, any
+ # TLD longer than that must be manually specified. The decisions behind this regular expression were made
+ # by reading this website: http://www.regular-expressions.info/email.html, which is an excellent resource
+ # for regular expressions.
+ def self.email
+ return @email_regex if @email_regex
+ email_name_regex = '[A-Z0-9_\.%\+\-]+'
+ domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
+ domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)'
+ @email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
+ end
+
+ def self.http_url
+ return @http_url if @http_url
+ @http_url = Regexp.new("^(?:http|https):(?:#{NET_PATH})(?:\\?(?:#{QUERY}))?$", Regexp::EXTENDED, 'N')
+ end
+ end
+
+ attribute :name
+ attribute :url
+ attribute :match_text
+ attribute :threshold
+ attribute :email
+ list :test_record
+
+ index :url
+
+ assert_present :name
+ assert_present :url
+ assert_present :threshold
+ assert_present :email
+
+ assert_format :email, Regex.email
+ assert_format :url, Regex.http_url
+end
@@ -0,0 +1,5 @@
+class Main
+ get "/" do
+ mustache :index
+ end
+end
@@ -0,0 +1,14 @@
+class Main
+ get "/sites/new" do
+ mustache :new_site
+ end
+
+ post '/sites' do
+ @site = Site.new(params['site'])
+ if @site.save
+
+ else
+
+ end
+ end
+end
@@ -0,0 +1,4 @@
+<h1>Watch Dog</h1>
+<p>
+ <a href="/sites/new">Add Site to Watch</a>
+</p>
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+ {{{yield}}}
+</body>
+</html>
No changes.
@@ -0,0 +1,12 @@
+<div id="site-form-wrapper">
+ <form action="/sites">
+ <fieldset>
+ {{{name_input}}}
+ {{{url_input}}}
+ {{{url_input}}}
+ {{{text_match_input}}}
+ {{{threshold_input}}}
+ {{{email_input}}}
+ </fieldset>
+ </form>
+</div>
@@ -0,0 +1,7 @@
+class Main
+ module Views
+ class Index < Mustache
+ include Main::Helpers::AppHelper
+ end
+ end
+end
@@ -0,0 +1,4 @@
+class MonitCheck < Mustache
+ path = root_path('app', 'templates')
+ template_extension = "mustache"
+end
@@ -0,0 +1,9 @@
+class Main
+ module Views
+ class NewSite < Mustache
+ include Main::Helpers::AppHelper
+ include Main::Helpers::SitesHelper
+
+ end
+ end
+end
@@ -0,0 +1,6 @@
+require "init"
+
+Main.set :run, false
+Main.set :environment, :production
+
+run Main
@@ -0,0 +1,12 @@
+defaults: &defaults
+ :log_level: warn
+
+:development:
+ <<: *defaults
+ :log_level: debug
+
+:test:
+ <<: *defaults
+
+:production:
+ <<: *defaults
@@ -0,0 +1,13 @@
+dependencies 0.0.7 git://github.com/djanowski/dependencies.git
+monk-glue git://github.com/monkrb/glue.git
+quietbacktrace 0.1.1 git://github.com/thoughtbot/quietbacktrace.git
+rack 1.0.0 git://github.com/rack/rack.git
+sinatra 0.9.4 git://github.com/sinatra/sinatra.git
+mustache 0.2.2 git://github.com/defunkt/mustache.git
+activesupport 2.3.4
+contest 0.1.2 (test) git://github.com/citrusbyte/contest.git
+stories 0.1.3 (test) git://github.com/citrusbyte/stories.git
+faker 0.3.1 (test) git://github.com/yyyc514/faker.git
+rack-test 0.5.0 (test) git://github.com/brynary/rack-test.git
+webrat 0.5.3 (test) git://github.com/brynary/webrat.git
+ohm git://github.com/brianjlandau/ohm.git
32 init.rb
@@ -0,0 +1,32 @@
+ROOT_DIR = File.expand_path(File.dirname(__FILE__)) unless defined? ROOT_DIR
+
+require "rubygems"
+
+begin
+ require "vendor/dependencies/lib/dependencies"
+rescue LoadError
+ require "dependencies"
+end
+
+require "monk/glue"
+require 'active_support'
+require 'mustache/sinatra'
+require 'ohm'
+
+class Main < Monk::Glue
+ set :app_file, __FILE__
+ use Rack::Session::Cookie
+ register Mustache::Sinatra
+ set :views, root_path('app', 'templates')
+ set :mustaches, root_path('app', 'views')
+
+ configure do
+ Ohm.connect
+ # Load all application files.
+ Dir[root_path("app/**/*.rb")].each do |file|
+ require file
+ end
+ end
+end
+
+Main.run! if Main.run?
No changes.
No changes.
@@ -0,0 +1,2 @@
+#!/bin/bash
+irb -r init.rb $*
@@ -0,0 +1,2 @@
+#!/bin/bash
+ruby init.rb
@@ -0,0 +1,11 @@
+require "stories_helper"
+
+class SiteTest < Test::Unit::TestCase
+ story "As a developer I want to see the homepage so I know Monk is correctly installed" do
+ scenario "A visitor goes to the homepage" do
+ visit "/"
+
+ assert_contain "Hello, world!"
+ end
+ end
+end
@@ -0,0 +1,16 @@
+require "test_helper"
+
+require "webrat"
+require "rack/test"
+require "stories"
+require "stories/runner"
+
+Webrat.configure do |config|
+ config.mode = :rack
+end
+
+class Test::Unit::TestCase
+ include Webrat::Methods
+ include Webrat::Matchers
+ include Stories::Webrat
+end
@@ -0,0 +1,18 @@
+ENV['RACK_ENV'] = 'test'
+
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
+
+require "rack/test"
+require "contest"
+require "quietbacktrace"
+require 'active_support/test_case'
+
+class Test::Unit::TestCase
+ include Rack::Test::Methods
+ include ActiveSupport::Testing::SetupAndTeardown
+ include ActiveSupport::Testing::Assertions
+
+ def app
+ Main.new
+ end
+end
Oops, something went wrong.

0 comments on commit d3a1134

Please sign in to comment.