Skip to content

Commit

Permalink
Plugin generator + exception template
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jan 22, 2008
1 parent ab75de9 commit 322d894
Show file tree
Hide file tree
Showing 17 changed files with 485 additions and 102 deletions.
98 changes: 12 additions & 86 deletions merb-gen/app_generators/merb/merb_generator.rb
@@ -1,94 +1,20 @@
class MerbGenerator < RubiGen::Base
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
Config::CONFIG['ruby_install_name']) unless defined? DEFAULT_SHEBANG

default_options :shebang => DEFAULT_SHEBANG

attr_reader :name

def initialize(runtime_args, runtime_options = {})
super
usage if args.empty?
@name = args.shift
@destination_root = File.expand_path(@name)
extract_options
end

def relative(path, dir = nil)
path.gsub(/^#{File.dirname(__FILE__)}\/templates\/#{dir}/, "")
end

def manifest
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
require "merb-gen/helpers"
require "merb-gen/base"

record do |m|
m.directory ''

options["spec"] = true unless options["test"]

# Things that are optional and should only be included if options[choice] is true
choices = %w( spec test )

# Make sure the appropriate folders exist
basedirs = Dir["#{File.dirname(__FILE__)}/templates/**/*"].
select {|x| File.directory?(x) && (!choices.include?(relative(x)) || options[relative(x)]) }.
map {|x| relative(x) }

basedirs.each { |path| m.directory path }

# copy skeleton
# Grab everything under templates
Dir["#{File.dirname(__FILE__)}/templates/**/*"].each do |file|
# Only continue if the file is a directory
next unless File.directory?(file)
next if (choices.include?(relative(file)) && !options[relative(file)])
# Remove "template/" from the glob filename
dir = relative(file)
# Get all the files under the directory that are not directories or in the list of excluded templates above.
# Then, remove "template/" from the resulting filenames
files = Dir["#{file}/*"].reject {|f| File.directory?(f)}.map {|f| relative(f, "#{dir}/") }
# Copy the files over
m.file_copy_each(files, dir) unless files.empty?
end

# m.template "config/merb.yml", "config/merb.yml", :assigns => {:key => "#{@name.upcase}#{rand(9999)}"}
end
end
class MerbGenerator < Merb::GeneratorBase

def windows
(RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)
def initialize(args, runtime_options = {})
@base = File.dirname(__FILE__)
super
end

protected
def banner
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
Creates a Merb application stub.
USAGE: #{spec.name} -g path"
EOS
end
def banner
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
Creates a Merb application stub.
def add_options!(opts)
opts.on("-S", "--[no-]spec", "Generate with RSpec") {|s| @options["spec"] = true}
opts.on("-T", "--[no-]test", "Generate with Test::Unit") {|t| @options["test"] = true}
end

def extract_options
end

def parse!(args, runtime_options = {})
self.options = {}

@option_parser = OptionParser.new do |opt|
opt.banner = banner
add_options!(opt)
add_general_options!(opt)
opt.parse!(args)
end
USAGE: #{spec.name} -g path"
EOS
end

return args
ensure
self.options = full_options(runtime_options)
end

end
@@ -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><%= @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>
20 changes: 20 additions & 0 deletions merb-gen/app_generators/merb_plugin/merb_plugin_generator.rb
@@ -0,0 +1,20 @@
require "merb-gen/helpers"
require "merb-gen/base"

class MerbPluginGenerator < Merb::GeneratorBase

def initialize(args, runtime_options = {})
@base = File.dirname(__FILE__)
super
end

protected
def banner
<<-EOS.split("\n").map{|x| x.strip}.join("\n")
Creates a Merb plugin stub.
USAGE: #{spec.name} --generate-plugin path"
EOS
end

end
20 changes: 20 additions & 0 deletions merb-gen/app_generators/merb_plugin/templates/LICENSE
@@ -0,0 +1,20 @@
Copyright (c) <%= Time.now.year %> YOUR NAME

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.
4 changes: 4 additions & 0 deletions merb-gen/app_generators/merb_plugin/templates/README
@@ -0,0 +1,4 @@
<%= base_name %>
<%= "=" * base_name.size %>

A plugin for the Merb framework that provides ...

0 comments on commit 322d894

Please sign in to comment.