From 42b82e59747482a4177ef7b2398f1c3cd2df8ffc Mon Sep 17 00:00:00 2001 From: Adam McCrea Date: Tue, 14 Apr 2009 08:23:09 -0400 Subject: [PATCH] initial commit --- MIT-LICENSE | 20 +++++++++++ Rakefile | 23 ++++++++++++ app/controllers/mockups_controller.rb | 48 +++++++++++++++++++++++++ app/views/mockups/frameset.html.erb | 13 +++++++ app/views/mockups/index.html.erb | 27 ++++++++++++++ config/routes.rb | 7 ++++ generators/showoff/USAGE | 8 +++++ generators/showoff/showoff_generator.rb | 8 +++++ init.rb | 5 +++ test/showoff_test.rb | 8 +++++ test/test_helper.rb | 3 ++ 11 files changed, 170 insertions(+) create mode 100644 MIT-LICENSE create mode 100644 Rakefile create mode 100644 app/controllers/mockups_controller.rb create mode 100644 app/views/mockups/frameset.html.erb create mode 100644 app/views/mockups/index.html.erb create mode 100644 config/routes.rb create mode 100644 generators/showoff/USAGE create mode 100644 generators/showoff/showoff_generator.rb create mode 100644 init.rb create mode 100644 test/showoff_test.rb create mode 100644 test/test_helper.rb diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..9376605 --- /dev/null +++ b/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. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a13d5fe --- /dev/null +++ b/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 diff --git a/app/controllers/mockups_controller.rb b/app/controllers/mockups_controller.rb new file mode 100644 index 0000000..a9a9a3d --- /dev/null +++ b/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 diff --git a/app/views/mockups/frameset.html.erb b/app/views/mockups/frameset.html.erb new file mode 100644 index 0000000..f6c0f6d --- /dev/null +++ b/app/views/mockups/frameset.html.erb @@ -0,0 +1,13 @@ + + + + + Mockups + + + + + + + + diff --git a/app/views/mockups/index.html.erb b/app/views/mockups/index.html.erb new file mode 100644 index 0000000..6e1d110 --- /dev/null +++ b/app/views/mockups/index.html.erb @@ -0,0 +1,27 @@ + + + + + <%= stylesheet_link_tag 'mockups.css' %> + + + + + + + diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..64c318e --- /dev/null +++ b/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 diff --git a/generators/showoff/USAGE b/generators/showoff/USAGE new file mode 100644 index 0000000..8113bfb --- /dev/null +++ b/generators/showoff/USAGE @@ -0,0 +1,8 @@ +Description: + Explain the generator + +Example: + ./script/generate mockups Thing + + This will create: + what/will/it/create diff --git a/generators/showoff/showoff_generator.rb b/generators/showoff/showoff_generator.rb new file mode 100644 index 0000000..e1b16a6 --- /dev/null +++ b/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 diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..366b258 --- /dev/null +++ b/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') + diff --git a/test/showoff_test.rb b/test/showoff_test.rb new file mode 100644 index 0000000..457e29a --- /dev/null +++ b/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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..cf148b8 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,3 @@ +require 'rubygems' +require 'active_support' +require 'active_support/test_case' \ No newline at end of file