Skip to content
Browse files

initial commit: merb-gen skel

  • Loading branch information...
0 parents commit eceffff08edb910acbfb931ddfd57eafe302d2ff @rpl rpl committed Aug 15, 2008
75 Rakefile
@@ -0,0 +1,75 @@
+require 'rubygems'
+Gem.clear_paths
+Gem.path.unshift(File.join(File.dirname(__FILE__), "gems"))
+
+require 'rake'
+require 'rake/rdoctask'
+require 'rake/testtask'
+require 'spec/rake/spectask'
+require 'fileutils'
+
+##
+# requires frozen merb-core (from /framework)
+# adds the other components to the load path
+def require_frozen_framework
+ framework = File.join(File.dirname(__FILE__), "framework")
+ if File.directory?(framework)
+ puts "Running from frozen framework"
+ core = File.join(framework,"merb-core")
+ if File.directory?(core)
+ puts "using merb-core from #{core}"
+ $:.unshift File.join(core,"lib")
+ require 'merb-core'
+ end
+ more = File.join(framework,"merb-more")
+ if File.directory?(more)
+ Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
+ $:.unshift File.join(more,d,'lib')
+ end
+ end
+ plugins = File.join(framework,"merb-plugins")
+ if File.directory?(plugins)
+ Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
+ $:.unshift File.join(plugins,d,'lib')
+ end
+ end
+ require "merb-core/core_ext/kernel"
+ require "merb-core/core_ext/rubygems"
+ else
+ p "merb doesn't seem to be frozen in /framework"
+ require 'merb-core'
+ end
+end
+
+if ENV['FROZEN']
+ require_frozen_framework
+else
+ require 'merb-core'
+end
+
+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
+
+##############################################################################
+# ADD YOUR CUSTOM TASKS IN /lib/tasks
+# NAME YOUR RAKE FILES file_name.rake
+##############################################################################
2 app/controllers/application.rb
@@ -0,0 +1,2 @@
+class Application < Merb::Controller
+end
13 app/controllers/exceptions.rb
@@ -0,0 +1,13 @@
+class Exceptions < Application
+
+ # handle NotFound exceptions (404)
+ def not_found
+ render :format => :html
+ end
+
+ # handle NotAcceptable exceptions (406)
+ def not_acceptable
+ render :format => :html
+ end
+
+end
5 app/helpers/global_helpers.rb
@@ -0,0 +1,5 @@
+module Merb
+ module GlobalHelpers
+ # helpers defined here available to all views.
+ end
+end
216 app/views/exceptions/internal_server_error.html.erb
@@ -0,0 +1,216 @@
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title><%= @exception_name %></title>
+ <style type="text/css" media="screen">
+ body {
+ font-family:arial;
+ font-size:11px;
+ }
+ h1 {
+ font-size:48px;
+ letter-spacing:-4px;
+ margin:0;
+ line-height:36px;
+ color:#333;
+ }
+ h1 sup {
+ font-size: 0.5em;
+ }
+ h1 sup.error_500, h1 sup.error_400 {
+ color:#990E05;
+ }
+ h1 sup.error_100, h1 sup.error_200 {
+ color:#00BF10;
+ }
+ h1 sup.error_300 {
+ /* pretty sure you cant 'see' status 300
+ errors but if you could I think they
+ would be blue */
+ color:#1B2099;
+ }
+ h2 {
+ font-size:36px;
+ letter-spacing:-3px;
+ margin:0;
+ line-height:28px;
+ color:#444;
+ }
+ a, a:visited {
+ color:#00BF10;
+ }
+ .internalError {
+ width:800px;
+ margin:50px auto;
+ }
+ .header {
+ border-bottom:10px solid #333;
+ margin-bottom:1px;
+ background-image: url("data:image/gif;base64,R0lGODlhAwADAIAAAP///8zMzCH5BAAAAAAALAAAAAADAAMAAAIEBHIJBQA7");
+ padding:20px;
+ }
+ table.trace {
+ width:100%;
+ font-family:courier, monospace;
+ letter-spacing:-1px;
+ border-collapse: collapse;
+ border-spacing:0;
+ }
+ table.trace tr td{
+ padding:0;
+ height:26px;
+ font-size:13px;
+ vertical-align:middle;
+ }
+ table.trace tr.file{
+ border-top:2px solid #fff;
+ background-color:#F3F3F3;
+ }
+ table.trace tr.source {
+ background-color:#F8F8F8;
+ display:none;
+ }
+ table.trace .open tr.source {
+ display:table-row;
+ }
+ table.trace tr.file td.expand {
+ width:23px;
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAdVJREFUeNqMVL+TwUAYxaRIOlEhlZHGDAUzzOQ61+AqXMV1lJSU7q/QRqm8KFUcJTNn5qJkaPyoKKVz7y4mF8na5Kt29tt9+/Z97/u81+vVQ4r9frdarS6Xi7ETDIZisRjxMGPfmk4niNPpZE+xLAugbPaZ53nzvtfMBe/3+/3dbuehBrAKhZdUKkVAWa9Xsiybv0CPZDJZLr/qa5/BwgwRjYqOKIvFYjQa/aNommZh0Ww2K5UqzwfoQOPxaLPZ3FAmk0+7lplMpt1u53J5OpBOR0eZEE9wHJfP5zud93g88QhluwWbjW+5VOmKBgKBer3eaDTDYeGBQF8+x7rqIYoiPgixWJazpA6HA+MSxRArkUgMh0M409g8Ho8+9wYxxCqVSq1W26EDHGM2m4HOHQrEc38f/Yn7cLmlIRhBENzcx8cVRZnPZ/YUep2BWkjTIfA+PKVpZAXR5QxsjiqCKvGEqqp443w+0dvy17swqD0HB3S73V5PpkNg1qBqt8kwGCjmPkinM0QJbIoEa7U6UG6ToVgs4V9G2g0ESoP5Aoi7KYX5oCgf8IKbkvn9/mr1LRQKESamzgJy0g0tSZIuB3nuGqRU9Vv9C4sKkUhEkp4soxvxI8AAhWrrtXa3X8EAAAAASUVORK5CYII=);
+ background-position:top left;
+ background-repeat:no-repeat;
+ }
+ table.trace .open tr.file td.expand {
+ width:19px;
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAB1CAIAAAAqdO2mAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAXZJREFUeNrslK1ywkAUhcMOBomEOiSdqLxEBJX0NaijOsjyHGGmCGyQQYaiiiw4gktkcOmZbpsuuzQ/M5XnqJ2d3S/n3nM3rTzPLUP7/Tt0+pLcGQwG3W53OLyHzPMtjYL7q9UqSRLrD4E1Gj1orCvKYuFHUWTVkOM44/HjDcp8/lL4r6NerzeZPMm1KFw0QkDn83m5fP2lHA4fNQvRtNvtjsfDd0WzmSfb2e/fdTqdOvdh/HLJZLOn0+d2HJ+KRGzbdl23EpFlmed5cp2maRzHQq1lvQ5KMi6EUZBGfup6E1pTfd+vrGW7jbQ2C9hTt9BpqNyIWaAwAy6xg2eBz5iRC/NomiZhGN5sqmnkauo0BUGgVQoBjQ80oCACgNQdZHfTYBkF2mxCtWWAqunWpahxIDUt3QYUxIFQpJHyIWpXjinabKbbwItMHT+NyjchrP8QKaSQQgoppJBCCimkkEIKKaSQQgoppJBCCimkkEIKKaSo+hRgAEFD17X08O2NAAAAAElFTkSuQmCC);
+ background-position:top left;
+ background-repeat:no-repeat;
+ }
+ table.trace tr.source td.collapse {
+ width:19px;
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAB1CAIAAAAqdO2mAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVxJREFUeNrs0zFygkAUBmBlUkgJHdABlQwVkVJKKUxBYWbkALTxMJwhltyDFkss03IF8pudIcwaDaDl/6pd2P327b7d+eHwMXs4lNkzggoVKlSoUKFChQoVKlSoUKFChQoVKlSoUKFChQqVEYqm6ft9+qiSJEkYho7jTlcw2fd9NOI4nq4gEdFwXXe1Cqco63VkWVbXRTqLhTpOwQRpF7quR1E0TgGhqvLKUFCyoQqG/rks3O6kZKW/eRFpevOCoGTXVTcMQ5EyxyDEkML1c5RzuZOICIyXqn7JBVez6282MWrx731HOv2qB8Hri2lamNk0DfpVVdV1Peodappmmua8bdvzuc7zfNprzrLMth1FnGh/X8MjCAIQv/cFz/+65PcDh7rbvYv2ZUfdj+PxsyzLgVl0hKwgTqeqKApx2LeOc7t98zyv/1FWOgvx9RPii23bmL9cetJ8Ed8CDAC6aFW8bCzFhwAAAABJRU5ErkJggg==);
+ background-position:bottom left;
+ background-repeat:no-repeat;
+ background-color:#6F706F;
+ }
+ table.trace tr td.path {
+ padding-left:10px;
+ }
+ table.trace tr td.code {
+ padding-left:35px;
+ white-space: pre;
+ line-height:9px;
+ padding-bottom:10px;
+ }
+ table.trace tr td.code em {
+ font-weight:bold;
+ color:#00BF10;
+ }
+ table.trace tr td.code a {
+ width: 20px;
+ float: left;
+ }
+ table.trace tr td.code .more {
+ color:#666;
+ }
+ table.trace tr td.line {
+ width:30px;
+ text-align:right;
+ padding-right:4px;
+ }
+ .footer {
+ margin-top:5px;
+ font-size:11px;
+ color:#444;
+ text-align:right;
+ }
+ </style>
+</head>
+<body>
+ <div class="internalError">
+
+ <div class="header">
+ <h1><%= @exception_name %> <sup class="error_<%= @exception.class::STATUS %>"><%= @exception.class::STATUS %></sup></h1>
+ <% if show_details = ::Merb::Config[:exception_details] -%>
+ <h2><%=h @exception.message %></h2>
+ <% else -%>
+ <h2>Sorry about that...</h2>
+ <% end -%>
+ <h3>Parameters</h3>
+ <ul>
+ <% params[:original_params].each do |param, value| %>
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
+ <% end %>
+ <%= "<li>None</li>" if params[:original_params].empty? %>
+ </ul>
+
+ <h3>Session</h3>
+ <ul>
+ <% params[:original_session].each do |param, value| %>
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
+ <% end %>
+ <%= "<li>None</li>" if params[:original_session].empty? %>
+ </ul>
+
+ <h3>Cookies</h3>
+ <ul>
+ <% params[:original_cookies].each do |param, value| %>
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
+ <% end %>
+ <%= "<li>None</li>" if params[:original_cookies].empty? %>
+ </ul>
+ </div>
+
+ <% if show_details %>
+ <table class="trace">
+ <% @exception.backtrace.each_with_index do |line, index| %>
+ <tbody class="close">
+ <tr class="file">
+ <td class="expand">
+ </td>
+ <td class="path">
+ <%= (line.match(/^([^:]+)/)[1] rescue 'unknown').sub(/\/((opt|usr)\/local\/lib\/(ruby\/)?(gems\/)?(1.8\/)?(gems\/)?|.+\/app\/)/, '') %>
+ <% unless line.match(/\.erb:/) %>
+ in "<strong><%= line.match(/:in `(.+)'$/)[1] rescue '?' %></strong>"
+ <% else %>
+ (<strong>ERB Template</strong>)
+ <% end %>
+ </td>
+ <td class="line">
+ <a href="txmt://open?url=file://<%=file = (line.match(/^([^:]+)/)[1] rescue 'unknown')%>&amp;line=<%= lineno = line.match(/:([0-9]+):/)[1] rescue '?' %>"><%=lineno%></a>&nbsp;
+ </td>
+ </tr>
+ <tr class="source">
+ <td class="collapse">
+ </td>
+ <td class="code" colspan="2"><% (__caller_lines__(file, lineno, 5) rescue []).each do |llineno, lcode, lcurrent| %>
+<a href="txmt://open?url=file://<%=file%>&amp;line=<%=llineno%>"><%= llineno %></a><%='<em>' if llineno==lineno.to_i %><%= lcode.size > 90 ? CGI.escapeHTML(lcode[0..90])+'<span class="more">......</span>' : CGI.escapeHTML(lcode) %><%='</em>' if llineno==lineno.to_i %>
+<% end %>
+
+</td>
+ </tr>
+ </tbody>
+ <% end %>
+ </table>
+ <script type="text/javascript" charset="utf-8">
+ // swop the open & closed classes
+ els = document.getElementsByTagName('td');
+ for(i=0; i<els.length; i++){
+ if(els[i].className=='expand' || els[i].className=='collapse'){
+ els[i].onclick = function(e){
+ tbody = this.parentNode.parentNode;
+ if(tbody.className=='open'){
+ tbody.className='closed';
+ }else{
+ tbody.className='open';
+ }
+ }
+ }
+ }
+ </script>
+ <% end %>
+ <div class="footer">
+ lots of love, from <a href="#">merb</a>
+ </div>
+ </div>
+</body>
+</html>
63 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><%= params[:exception] %></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; 2007 the merb dev team</div>
+ <p>&nbsp;</p>
+ </div>
+</div>
47 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><%= params[:exception] %></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; 2007 the merb dev team</div>
+ <p>&nbsp;</p>
+ </div>
+</div>
1 autotest/discover.rb
@@ -0,0 +1 @@
+Autotest.add_discovery { "merb" }
149 autotest/merb.rb
@@ -0,0 +1,149 @@
+# 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)%
+
+ # 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 or 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
166 autotest/merb_rspec.rb
@@ -0,0 +1,166 @@
+# Adapted from Autotest::Rails, RSpec's autotest class, as well as merb-core's.
+require 'autotest'
+
+class RspecCommandError < StandardError; end
+
+# This class maps your application's structure so Autotest can understand what
+# specs to run when files change.
+#
+# Fixtures are _not_ covered by this class. If you change a fixture file, you
+# will have to run your spec suite manually, or, better yet, provide your own
+# Autotest map explaining how your fixtures are set up.
+class Autotest::MerbRspec < Autotest
+ def initialize
+ super
+
+ # Ignore any happenings in these directories
+ add_exception %r%^\./(?:doc|log|public|tmp)%
+
+ # 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
+
+ # Anything in /lib could have a spec anywhere, if at all. So, look for
+ # files with roughly the same name as the file in /lib
+ add_mapping %r%^lib\/(.*)\.rb% do |_, m|
+ files_matching %r%^spec\/#{m[1]}%
+ end
+
+ add_mapping %r%^spec/(spec_helper|shared/.*)\.rb$% do
+ all_specs
+ end
+
+ # Changing a spec will cause it to run itself
+ add_mapping %r%^spec/.*\.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|
+ spec_for(m[1], 'model')
+ end
+
+ # Any change to global_helpers will result in all view and controller
+ # tests being run
+ add_mapping %r%^app/helpers/global_helpers\.rb% do
+ files_matching %r%^spec/(views|controllers|helpers)/.*_spec\.rb$%
+ end
+
+ # Any change to a helper will cause its spec to be run
+ add_mapping %r%^app/helpers/((.*)_helper(s)?)\.rb% do |_, m|
+ spec_for(m[1], 'helper')
+ end
+
+ # Changes to a view cause its spec to be run
+ add_mapping %r%^app/views/(.*)/% do |_, m|
+ spec_for(m[1], 'view')
+ end
+
+ # Changes to a controller result in its corresponding spec being run. If
+ # the controller is the exception or application controller, all
+ # controller specs are run.
+ add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m|
+ if ["application", "exception"].include?(m[1])
+ files_matching %r%^spec/controllers/.*_spec\.rb$%
+ else
+ spec_for(m[1], 'controller')
+ end
+ end
+
+ # If a change is made to the router, run controller, view and helper specs
+ add_mapping %r%^config/router.rb$% do
+ files_matching %r%^spec/(controllers|views|helpers)/.*_spec\.rb$%
+ end
+
+ # If any of the major files governing the environment are altered, run
+ # everything
+ add_mapping %r%^config/(init|rack|environments/test).*\.rb|database\.yml% do
+ all_specs
+ end
+ end
+
+ def failed_results(results)
+ results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
+ end
+
+ def handle_results(results)
+ @failures = failed_results(results)
+ @files_to_test = consolidate_failures(@failures)
+ @files_to_test.empty? && !$TESTING ? hook(:green) : hook(:red)
+ @tainted = !@files_to_test.empty?
+ end
+
+ def consolidate_failures(failed)
+ filters = Hash.new { |h,k| h[k] = [] }
+ failed.each do |spec, failed_trace|
+ if f = test_files_for(failed).find { |f| f =~ /spec\// }
+ filters[f] << spec
+ break
+ end
+ end
+ filters
+ end
+
+ def make_test_cmd(specs_to_runs)
+ [
+ ruby,
+ "-S",
+ spec_command,
+ add_options_if_present,
+ files_to_test.keys.flatten.join(' ')
+ ].join(' ')
+ end
+
+ def add_options_if_present
+ File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
+ end
+
+ # Finds the proper spec command to use. Precendence is set in the
+ # lazily-evaluated method spec_commands. Alias + Override that in
+ # ~/.autotest to provide a different spec command then the default
+ # paths provided.
+ def spec_command(separator=File::ALT_SEPARATOR)
+ unless defined?(@spec_command)
+ @spec_command = spec_commands.find { |cmd| File.exists?(cmd) }
+
+ raise RspecCommandError, "No spec command could be found" unless @spec_command
+
+ @spec_command.gsub!(File::SEPARATOR, separator) if separator
+ end
+ @spec_command
+ end
+
+ # Autotest will look for spec commands in the following
+ # locations, in this order:
+ #
+ # * default spec bin/loader installed in Rubygems
+ # * any spec command found in PATH
+ def spec_commands
+ [File.join(Config::CONFIG['bindir'], 'spec'), 'spec']
+ end
+
+private
+
+ # Runs +files_matching+ for all specs
+ def all_specs
+ files_matching %r%^spec/.*_spec\.rb$%
+ end
+
+ # Generates a path to some spec given its kind and the match from a mapping
+ #
+ # ==== Arguments
+ # match<String>:: the match from a mapping
+ # kind<String>:: the kind of spec that the match represents
+ #
+ # ==== Returns
+ # String
+ #
+ # ==== Example
+ # > spec_for('post', :view')
+ # => "spec/views/post_spec.rb"
+ def spec_for(match, kind)
+ File.join("spec", kind + 's', "#{match}_spec.rb")
+ end
+end
7 config/environments/development.rb
@@ -0,0 +1,7 @@
+Merb.logger.info("Loaded DEVELOPMENT Environment...")
+Merb::Config.use { |c|
+ c[:exception_details] = true
+ c[:reload_classes] = true
+ c[:reload_time] = 0.5
+ c[:log_auto_flush ] = true
+}
7 config/environments/production.rb
@@ -0,0 +1,7 @@
+Merb.logger.info("Loaded PRODUCTION Environment...")
+Merb::Config.use { |c|
+ c[:exception_details] = false
+ c[:reload_classes] = false
+ c[:log_level] = :error
+ c[:log_file] = Merb.log_path + "/production.log"
+}
7 config/environments/rake.rb
@@ -0,0 +1,7 @@
+Merb.logger.info("Loaded RAKE Environment...")
+Merb::Config.use { |c|
+ c[:exception_details] = true
+ c[:reload_classes] = false
+ c[:log_auto_flush ] = true
+ c[:log_file] = Merb.log_path / 'merb_rake.log'
+}
6 config/environments/test.rb
@@ -0,0 +1,6 @@
+Merb.logger.info("Loaded TEST Environment...")
+Merb::Config.use { |c|
+ c[:testing] = true
+ c[:exception_details] = true
+ c[:log_auto_flush ] = true
+}
164 config/init.rb
@@ -0,0 +1,164 @@
+#
+# ==== Structure of Merb initializer
+#
+# 1. Load paths.
+# 2. Dependencies configuration.
+# 3. Libraries (ORM, testing tool, etc) you use.
+# 4. Application-specific configuration.
+
+#
+# ==== Set up load paths
+#
+
+# Add the app's "gems" directory to the gem load path.
+# Note that the gems directory must mirror the structure RubyGems uses for
+# directories under which gems are kept.
+#
+# To conveniently set it up, use gem install -i <merb_app_root/gems>
+# when installing gems. This will set up the structure under /gems
+# automagically.
+#
+# An example:
+#
+# You want to bundle ActiveRecord and ActiveSupport with your Merb
+# application to be deployment environment independent. To do so,
+# install gems into merb_app_root/gems directory like this:
+#
+# gem install -i merb_app_root/gems activesupport-post-2.0.2.gem activerecord-post-2.0.2.gem
+#
+# Since RubyGems will search merb_app_root/gems for dependencies, order
+# in the statement above is important: we need to install ActiveSupport which
+# ActiveRecord depends on first.
+#
+# Remember that bundling of dependencies as gems with your application
+# makes it independent of the environment it runs in and is a very
+# good, encouraged practice to follow.
+Gem.clear_paths
+Gem.path.unshift(Merb.root / "gems")
+
+# If you want modules and classes from libraries organized like
+# merbapp/lib/magicwand/lib/magicwand.rb to autoload,
+# uncomment this.
+# Merb.push_path(:lib, Merb.root / "lib") # uses **/*.rb as path glob.
+
+# ==== Dependencies
+
+# These are some examples of how you might specify dependencies.
+# Dependency loading is delayed to a later Merb app
+# boot stage, but it may be important when
+# another part of your configuration relies on libraries specified
+# here.
+#
+# dependencies "RedCloth", "merb_helpers"
+# OR
+# dependency "RedCloth", "> 3.0"
+# OR
+# dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0"
+Merb::BootLoader.after_app_loads do
+ # Add dependencies here that must load after the application loads:
+
+ # dependency "magic_admin" # this gem uses the app's model classes
+end
+
+#
+# ==== Set up your ORM of choice
+#
+
+# Merb doesn't come with database support by default. You need
+# an ORM plugin. Install one, and uncomment one of the following lines,
+# if you need a database.
+
+# Uncomment for DataMapper ORM
+use_orm :datamapper
+
+# Uncomment for ActiveRecord ORM
+# use_orm :activerecord
+
+# Uncomment for Sequel ORM
+# use_orm :sequel
+
+
+#
+# ==== Pick what you test with
+#
+
+# This defines which test framework the generators will use.
+# RSpec is turned on by default.
+#
+# To use Test::Unit, you need to install the merb_test_unit gem.
+# To use RSpec, you don't have to install any additional gems, since
+# merb-core provides support for RSpec.
+#
+# use_test :test_unit
+# use_test :rspec
+
+#
+# ==== Set up your basic configuration
+#
+
+# IMPORTANT:
+#
+# early on Merb boot init file is not yet loaded.
+# Thus setting PORT, PID FILE and ADAPTER using init file does not
+# make sense and only can lead to confusion because default settings
+# will be used instead.
+#
+# Please use command line options for them.
+# See http://wiki.merbivore.com/pages/merb-core-boot-process
+# if you want to know more.
+Merb::Config.use do |c|
+
+ # Sets up a custom session id key which is used for the session persistence
+ # cookie name. If not specified, defaults to '_session_id'.
+ # c[:session_id_key] = '_session_id'
+
+ # The session_secret_key is only required for the cookie session store.
+ c[:session_secret_key] = 'a1bf5d1183ee682103b80f20c814b57a7753b1bd'
+
+ # There are various options here, by default Merb comes with 'cookie',
+ # 'memory' or 'memcached'. You can of course use your favorite ORM
+ # instead: 'datamapper', 'sequel' or 'activerecord'.
+ c[:session_store] = 'cookie'
+end
+
+
+# ==== Tune your inflector
+
+# To fine tune your inflector use the word, singular_word and plural_word
+# methods of Language::English::Inflector module metaclass.
+#
+# Here we define erratum/errata exception case:
+#
+# Language::English::Inflector.word "erratum", "errata"
+#
+# In case singular and plural forms are the same omit
+# second argument on call:
+#
+# Language::English::Inflector.word 'information'
+#
+# You can also define general, singularization and pluralization
+# rules:
+#
+# Once the following rule is defined:
+# Language::English::Inflector.rule 'y', 'ies'
+#
+# You can see the following results:
+# irb> "fly".plural
+# => flies
+# irb> "cry".plural
+# => cries
+#
+# Example for singularization rule:
+#
+# Language::English::Inflector.singular_rule 'o', 'oes'
+#
+# Works like this:
+# irb> "heroes".singular
+# => hero
+#
+# Example of pluralization rule:
+# Language::English::Inflector.singular_rule 'fe', 'ves'
+#
+# And the result is:
+# irb> "wife".plural
+# => wives
12 config/rack.rb
@@ -0,0 +1,12 @@
+
+# use PathPrefix Middleware if :path_prefix is set in Merb::Config
+if prefix = ::Merb::Config[:path_prefix]
+ use Merb::Rack::PathPrefix, prefix
+end
+
+# comment this out if you are running merb behind a load balancer
+# that serves static files
+use Merb::Rack::Static, Merb.dir_for(:public)
+
+# this is our main merb application
+run Merb::Rack::Application.new
35 config/router.rb
@@ -0,0 +1,35 @@
+# Merb::Router is the request routing mapper for the merb framework.
+#
+# You can route a specific URL to a controller / action pair:
+#
+# r.match("/contact").
+# to(:controller => "info", :action => "contact")
+#
+# You can define placeholder parts of the url with the :symbol notation. These
+# placeholders will be available in the params hash of your controllers. For example:
+#
+# r.match("/books/:book_id/:action").
+# to(:controller => "books")
+#
+# Or, use placeholders in the "to" results for more complicated routing, e.g.:
+#
+# r.match("/admin/:module/:controller/:action/:id").
+# to(:controller => ":module/:controller")
+#
+# You can also use regular expressions, deferred routes, and many other options.
+# See merb/specs/merb/router.rb for a fairly complete usage sample.
+
+Merb.logger.info("Compiling routes...")
+Merb::Router.prepare do |r|
+ # RESTful routes
+ # r.resources :posts
+
+ # This is the default route for /:controller/:action/:id
+ # This is fine for most cases. If you're heavily using resource-based
+ # routes, you may want to comment/remove this line to prevent
+ # clients from calling your create or destroy actions with a GET
+ r.default_routes
+
+ # Change this for your home page to be available at /
+ # r.match('/').to(:controller => 'whatever', :action =>'index')
+end
BIN public/images/merb.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 public/merb.fcgi
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'merb-core'
+
+# this is Merb.root, change this if you have some funky setup.
+merb_root = File.expand_path(File.dirname(__FILE__) / '../')
+
+# If the fcgi process runs as apache, make sure
+# we have an inlinedir set for Rubyinline action-args to work
+unless ENV["INLINEDIR"] || ENV["HOME"]
+ tmpdir = merb_root / "tmp"
+ unless File.directory?(tmpdir)
+ Dir.mkdir(tmpdir)
+ end
+ ENV["INLINEDIR"] = tmpdir
+end
+
+# start merb with the fcgi adapter, add options or change the log dir here
+Merb.start(:adapter => 'fcgi',
+ :merb_root => merb_root,
+ :log_file => merb_root /'log'/'merb.log')
119 public/stylesheets/master.css
@@ -0,0 +1,119 @@
+body {
+ font-family: Arial, Verdana, sans-serif;
+ font-size: 12px;
+ background-color: #fff;
+}
+* {
+ margin: 0px;
+ padding: 0px;
+ text-decoration: none;
+}
+html {
+ height: 100%;
+ margin-bottom: 1px;
+}
+#container {
+ width: 80%;
+ text-align: left;
+ background-color: #fff;
+ margin-right: auto;
+ margin-left: auto;
+}
+#header-container {
+ width: 100%;
+ padding-top: 15px;
+}
+#header-container h1, #header-container h2 {
+ margin-left: 6px;
+ margin-bottom: 6px;
+}
+.spacer {
+ width: 100%;
+ height: 15px;
+}
+hr {
+ border: 0px;
+ color: #ccc;
+ background-color: #cdcdcd;
+ height: 1px;
+ width: 100%;
+ text-align: left;
+}
+h1 {
+ font-size: 28px;
+ color: #c55;
+ background-color: #fff;
+ font-family: Arial, Verdana, sans-serif;
+ font-weight: 300;
+}
+h2 {
+ font-size: 15px;
+ color: #999;
+ font-family: Arial, Verdana, sans-serif;
+ font-weight: 300;
+ background-color: #fff;
+}
+h3 {
+ color: #4d9b12;
+ font-size: 15px;
+ text-align: left;
+ font-weight: 300;
+ padding: 5px;
+ margin-top: 5px;
+}
+
+#left-container {
+ float: left;
+ width: 250px;
+ background-color: #FFFFFF;
+ color: black;
+}
+
+#left-container h3 {
+ color: #c55;
+}
+
+#main-container {
+ margin: 5px 5px 5px 260px;
+ padding: 15px;
+ border-left: 1px solid silver;
+ min-height: 400px;
+}
+p {
+ color: #000;
+ background-color: #fff;
+ line-height: 20px;
+ padding: 5px;
+}
+a {
+ color: #4d9b12;
+ background-color: #fff;
+ text-decoration: none;
+}
+a:hover {
+ color: #4d9b12;
+ background-color: #fff;
+ text-decoration: underline;
+}
+#footer-container {
+ clear: both;
+ font-size: 12px;
+ font-family: Verdana, Arial, sans-serif;
+}
+.right {
+ float: right;
+ font-size: 100%;
+ margin-top: 5px;
+ color: #999;
+ background-color: #fff;
+}
+.left {
+ float: left;
+ font-size: 100%;
+ margin-top: 5px;
+ color: #999;
+ background-color: #fff;
+}
+#main-container ul {
+ margin-left: 3.0em;
+}
0 spec/spec.opts
No changes.
13 spec/spec_helper.rb
@@ -0,0 +1,13 @@
+require 'rubygems'
+require 'merb-core'
+require 'spec' # Satisfies Autotest and anyone else not using the Rake tasks
+
+# this loads all plugins required in your init file so don't add them
+# here again, Merb will do it for you
+Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
+
+Spec::Runner.configure do |config|
+ config.include(Merb::Test::ViewHelper)
+ config.include(Merb::Test::RouteHelper)
+ config.include(Merb::Test::ControllerHelper)
+end
14 test/test_helper.rb
@@ -0,0 +1,14 @@
+$TESTING=true
+require 'rubygems'
+require 'merb-core'
+
+
+# TODO: Boot Merb, via the Test Rack adapter
+Merb.start :environment => (ENV['MERB_ENV'] || 'test'),
+ :merb_root => File.join(File.dirname(__FILE__), ".." )
+
+
+class Test::Unit::TestCase
+ include Merb::Test::RequestHelper
+ # Add more helper methods to be used by all tests here...
+end

0 comments on commit eceffff

Please sign in to comment.
Something went wrong with that request. Please try again.