Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed Apr 14, 2009
1 parent 453fa2c commit 42b82e5
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2009 [name of plugin creator]

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.
23 changes: 23 additions & 0 deletions Rakefile
@@ -0,0 +1,23 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the showoff plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the showoff plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Showoff'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
48 changes: 48 additions & 0 deletions app/controllers/mockups_controller.rb
@@ -0,0 +1,48 @@
class MockupsController < ApplicationController

def frameset
render :layout => false
end

def index
@entries = ActiveSupport::OrderedHash.new

Dir.glob File.join(Rails.root, 'app', 'views', 'mockups', '**', '[^_]*.html.*') do |template|
parent_dir = File.dirname(template).split(/[\/]/).last
template_name = File.basename(template).split('.').first

if parent_dir == 'mockups'
@entries[template_name] = nil
else
(@entries[parent_dir] ||= []) << template_name
end
end

# @pages = template_files.map { |f| f.scan(/mockups\/([^.]+)/).flatten.first }

render :layout => false
end

def show
template_path = File.join(['mockups', params[:parent_dir], params[:template_name]].compact)
render :template => template_path, :layout => extract_layout(template_path)
end

private

def extract_layout(template_path)
full_path = File.join(Rails.root, 'app', 'views', template_path)
located_files = Dir.glob("#{full_path}*")

return true if located_files.empty?

filename_components = File.basename(located_files[0]).split('.')

if filename_components[1] == 'html'
true
else
filename_components[1]
end
end

end
13 changes: 13 additions & 0 deletions app/views/mockups/frameset.html.erb
@@ -0,0 +1,13 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
<title>Mockups</title>
</head>

<frameset cols="200,*" frameborder="1" border="1" bordercolor="#666666" framespacing="1">
<frame src="/mockups_index" title="List" name="list" />
<frame name="content" />
</frameset>

</html>
27 changes: 27 additions & 0 deletions app/views/mockups/index.html.erb
@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
<%= stylesheet_link_tag 'mockups.css' %>
</head>

<body>
<ul id="mockups_tree">
<% @entries.each do |name, mockups| %>
<li>
<% if mockups.nil? %>
<%= link_to name.humanize, mockup_path(name), :target => 'content' %>
<% else %>
<h2><%= name.humanize.titleize %></h2>
<ul>
<% mockups.each do |mockup| %>
<li><%= link_to mockup.humanize, mockup_path(mockup, :parent_dir => name), :target => 'content' %></li>
<% end %>
</ul>
<% end %>
</li>
<% end %>
</ul>
</body>

</html>
7 changes: 7 additions & 0 deletions config/routes.rb
@@ -0,0 +1,7 @@
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => 'mockups' do |mockups|
mockups.mockups '/mockups', :action => 'frameset'
mockups.mockups_index '/mockups_index', :action => 'index'
mockups.mockup '/mockup/:template_name', :action => 'show'
end
end
8 changes: 8 additions & 0 deletions generators/showoff/USAGE
@@ -0,0 +1,8 @@
Description:
Explain the generator

Example:
./script/generate mockups Thing

This will create:
what/will/it/create
8 changes: 8 additions & 0 deletions generators/showoff/showoff_generator.rb
@@ -0,0 +1,8 @@
class ShowoffGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# m.directory "lib"
# m.template 'README', "README"
end
end
end
5 changes: 5 additions & 0 deletions init.rb
@@ -0,0 +1,5 @@

# Since MockupsController subclasses (and thus loads) ApplicationController, we need to make sure that
# it gets reloaded in development. Without this, things will break after the first reload.
ActiveSupport::Dependencies.load_once_paths.delete(File.expand_path(File.dirname(__FILE__))+'/app/controllers')

8 changes: 8 additions & 0 deletions test/showoff_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class ShowoffTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'

0 comments on commit 42b82e5

Please sign in to comment.