Skip to content

Commit

Permalink
Initial create app
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Persky committed Dec 6, 2008
0 parents commit 870d2a0
Show file tree
Hide file tree
Showing 44 changed files with 8,822 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
@@ -0,0 +1,18 @@
.DS_Store
log/*
tmp/*
TAGS
*~
.#*
schema/schema.rb
schema/*_structure.sql
schema/*.sqlite3
schema/*.sqlite
schema/*.db
*.sqlite
*.sqlite3
*.db
src/*
.hgignore
.hg/*
.svn/*
35 changes: 35 additions & 0 deletions Rakefile
@@ -0,0 +1,35 @@
require 'rubygems'
require 'rake/rdoctask'

require 'merb-core'
require 'merb-core/tasks/merb'

include FileUtils

# Load the basic runtime dependencies; this will include
# any plugins and therefore plugin rake tasks.
init_env = ENV['MERB_ENV'] || 'rake'
Merb.load_dependencies(:environment => init_env)

# Get Merb plugins and dependencies
Merb::Plugins.rakefiles.each { |r| require r }

# Load any app level custom rakefile extensions from lib/tasks
tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks")
rake_files = Dir["#{tasks_path}/*.rake"]
rake_files.each{|rake_file| load rake_file }

desc "Start runner environment"
task :merb_env do
Merb.start_environment(:environment => init_env, :adapter => 'runner')
end

require 'spec/rake/spectask'
require 'merb-core/test/tasks/spectasks'
desc 'Default: run spec examples'
task :default => 'spec'

##############################################################################
# ADD YOUR CUSTOM TASKS IN /lib/tasks
# NAME YOUR RAKE FILES file_name.rake
##############################################################################
2 changes: 2 additions & 0 deletions app/controllers/application.rb
@@ -0,0 +1,2 @@
class Application < Merb::Controller
end
13 changes: 13 additions & 0 deletions app/controllers/exceptions.rb
@@ -0,0 +1,13 @@
class Exceptions < Merb::Controller

# handle NotFound exceptions (404)
def not_found
render :format => :html
end

# handle NotAcceptable exceptions (406)
def not_acceptable
render :format => :html
end

end
5 changes: 5 additions & 0 deletions app/helpers/global_helpers.rb
@@ -0,0 +1,5 @@
module Merb
module GlobalHelpers
# helpers defined here available to all views.
end
end
17 changes: 17 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,17 @@
# This is a default user class used to activate merb-auth. Feel free to change from a User to
# Some other class, or to remove it altogether. If removed, merb-auth may not work by default.
#
# Don't forget that by default the salted_user mixin is used from merb-more
# You'll need to setup your db as per the salted_user mixin, and you'll need
# To use :password, and :password_confirmation when creating a user
#
# see merb/merb-auth/setup.rb to see how to disable the salted_user mixin
#
# You will need to setup your database and create a user.
class User
include DataMapper::Resource

property :id, Serial
property :login, String

end
63 changes: 63 additions & 0 deletions app/views/exceptions/not_acceptable.html.erb
@@ -0,0 +1,63 @@
<div id="container">
<div id="header-container">
<img src="/images/merb.jpg" />
<!-- <h1>Mongrel + Erb</h1> -->
<h2>pocket rocket web framework</h2>
<hr />
</div>

<div id="left-container">
<h3>Exception:</h3>
<p><%= request.exceptions.first.message %></p>
</div>

<div id="main-container">
<h3>Why am I seeing this page?</h3>
<p>Merb couldn't find an appropriate content_type to return,
based on what you said was available via provides() and
what the client requested.</p>

<h3>How to add a mime-type</h3>
<pre><code>
Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], &quot;Content-Encoding&quot; =&gt; &quot;gzip&quot;
</code></pre>
<h3>What this means is:</h3>
<ul>
<li>Add a mime-type for :pdf</li>
<li>Register the method for converting objects to PDF as <code>#to_pdf</code>.</li>
<li>Register the incoming mime-type "Accept" header as <code>application/pdf</code>.</li>
<li>Specify a new header for PDF types so it will set <code>Content-Encoding</code> to gzip.</li>
</ul>

<h3>You can then do:</h3>
<pre><code>
class Foo &lt; Application
provides :pdf
end
</code></pre>

<h3>Where can I find help?</h3>
<p>If you have any questions or if you can't figure something out, please take a
look at our <a href="http://merbivore.com/"> project page</a>,
feel free to come chat at irc.freenode.net, channel #merb,
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
on Google Groups.</p>

<h3>What if I've found a bug?</h3>
<p>If you want to file a bug or make your own contribution to Merb,
feel free to register and create a ticket at our
<a href="http://merb.lighthouseapp.com/">project development page</a>
on Lighthouse.</p>

<h3>How do I edit this page?</h3>
<p>You can change what people see when this happens by editing <tt>app/views/exceptions/not_acceptable.html.erb</tt>.</p>

</div>

<div id="footer-container">
<hr />
<div class="left"></div>
<div class="right">&copy; 2008 the merb dev team</div>
<p>&nbsp;</p>
</div>
</div>
47 changes: 47 additions & 0 deletions app/views/exceptions/not_found.html.erb
@@ -0,0 +1,47 @@
<div id="container">
<div id="header-container">
<img src="/images/merb.jpg" />
<!-- <h1>Mongrel + Erb</h1> -->
<h2>pocket rocket web framework</h2>
<hr />
</div>

<div id="left-container">
<h3>Exception:</h3>
<p><%= request.exceptions.first.message %></p>
</div>

<div id="main-container">
<h3>Welcome to Merb!</h3>
<p>Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.</p>

<h3>Where can I find help?</h3>
<p>If you have any questions or if you can't figure something out, please take a
look at our <a href="http://merbivore.com/"> project page</a>,
feel free to come chat at irc.freenode.net, channel #merb,
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
on Google Groups.</p>

<h3>What if I've found a bug?</h3>
<p>If you want to file a bug or make your own contribution to Merb,
feel free to register and create a ticket at our
<a href="http://merb.lighthouseapp.com/">project development page</a>
on Lighthouse.</p>

<h3>How do I edit this page?</h3>
<p>You're seeing this page because you need to edit the following files:
<ul>
<li>config/router.rb <strong><em>(recommended)</em></strong></li>
<li>app/views/exceptions/not_found.html.erb <strong><em>(recommended)</em></strong></li>
<li>app/views/layout/application.html.erb <strong><em>(change this layout)</em></strong></li>
</ul>
</p>
</div>

<div id="footer-container">
<hr />
<div class="left"></div>
<div class="right">&copy; 2008 the merb dev team</div>
<p>&nbsp;</p>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/layout/application.html.erb
@@ -0,0 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title>Fresh Merb App</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8" />
</head>
<body>
<%#= message[:notice] %>
<%= catch_content :for_layout %>
</body>
</html>
2 changes: 2 additions & 0 deletions autotest/discover.rb
@@ -0,0 +1,2 @@
Autotest.add_discovery { "merb" }
Autotest.add_discovery { "rspec" }
152 changes: 152 additions & 0 deletions autotest/merb.rb
@@ -0,0 +1,152 @@
# Adapted from Autotest::Rails
require 'autotest'

class Autotest::Merb < Autotest

# +model_tests_dir+:: the directory to find model-centric tests
# +controller_tests_dir+:: the directory to find controller-centric tests
# +view_tests_dir+:: the directory to find view-centric tests
# +fixtures_dir+:: the directory to find fixtures in
attr_accessor :model_tests_dir, :controller_tests_dir, :view_tests_dir, :fixtures_dir

def initialize
super

initialize_test_layout

# Ignore any happenings in these directories
add_exception %r%^\./(?:doc|log|public|tmp|\.git|\.hg|\.svn|framework|gems|schema|\.DS_Store|autotest|bin|.*\.sqlite3)%
# Ignore SCM directories and custom Autotest mappings
%w[.svn .hg .git .autotest].each { |exception| add_exception(exception) }


# Ignore any mappings that Autotest may have already set up
clear_mappings

# Any changes to a file in the root of the 'lib' directory will run any
# model test with a corresponding name.
add_mapping %r%^lib\/.*\.rb% do |filename, _|
files_matching Regexp.new(["^#{model_test_for(filename)}$"])
end

# Any changes to a fixture will run corresponding view, controller and
# model tests
add_mapping %r%^#{fixtures_dir}/(.*)s.yml% do |_, m|
[
model_test_for(m[1]),
controller_test_for(m[1]),
view_test_for(m[1])
]
end

# Any change to a test will cause it to be run
add_mapping %r%^test/(unit|models|integration|controllers|views|functional)/.*rb$% do |filename, _|
filename
end

# Any change to a model will cause it's corresponding test to be run
add_mapping %r%^app/models/(.*)\.rb$% do |_, m|
model_test_for(m[1])
end

# Any change to the global helper will result in all view and controller
# tests being run
add_mapping %r%^app/helpers/global_helpers.rb% do
files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
end

# Any change to a helper will run it's corresponding view and controller
# tests, unless the helper is the global helper. Changes to the global
# helper run all view and controller tests.
add_mapping %r%^app/helpers/(.*)_helper(s)?.rb% do |_, m|
if m[1] == "global" then
files_matching %r%^test/(views|functional|controllers)/.*_test\.rb$%
else
[
view_test_for(m[1]),
controller_test_for(m[1])
]
end
end

# Changes to views result in their corresponding view and controller test
# being run
add_mapping %r%^app/views/(.*)/% do |_, m|
[
view_test_for(m[1]),
controller_test_for(m[1])
]
end

# Changes to a controller result in its corresponding test being run. If
# the controller is the exception or application controller, all
# controller tests are run.
add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
if ["application", "exception"].include?(m[1])
files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
else
controller_test_for(m[1])
end
end

# If a change is made to the router, run all controller and view tests
add_mapping %r%^config/router.rb$% do # FIX
files_matching %r%^test/(controllers|views|functional)/.*_test\.rb$%
end

# If any of the major files governing the environment are altered, run
# everything
add_mapping %r%^test/test_helper.rb|config/(init|rack|environments/test.rb|database.yml)% do # FIX
files_matching %r%^test/(unit|models|controllers|views|functional)/.*_test\.rb$%
end
end

private

# Determines the paths we can expect tests or specs to reside, as well as
# corresponding fixtures.
def initialize_test_layout
self.model_tests_dir = "test/unit"
self.controller_tests_dir = "test/functional"
self.view_tests_dir = "test/views"
self.fixtures_dir = "test/fixtures"
end

# Given a filename and the test type, this method will return the
# corresponding test's or spec's name.
#
# ==== Arguments
# +filename+<String>:: the file name of the model, view, or controller
# +kind_of_test+<Symbol>:: the type of test we that we should run
#
# ==== Returns
# String:: the name of the corresponding test or spec
#
# ==== Example
#
# > test_for("user", :model)
# => "user_test.rb"
# > test_for("login", :controller)
# => "login_controller_test.rb"
# > test_for("form", :view)
# => "form_view_spec.rb" # If you're running a RSpec-like suite
def test_for(filename, kind_of_test)
name = [filename]
name << kind_of_test.to_s if kind_of_test == :view
name << "test"
return name.join("_") + ".rb"
end

def model_test_for(filename)
[model_tests_dir, test_for(filename, :model)].join("/")
end

def controller_test_for(filename)
[controller_tests_dir, test_for(filename, :controller)].join("/")
end

def view_test_for(filename)
[view_tests_dir, test_for(filename, :view)].join("/")
end

end

0 comments on commit 870d2a0

Please sign in to comment.