Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
Thanks Vesa Vänskä, Matias Korhonen, and Antti Salonen for all the
contributions to this gem.
  • Loading branch information
jcxplorer committed Jun 7, 2011
0 parents commit ee2c6e3
Show file tree
Hide file tree
Showing 51 changed files with 718 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.bundle/
log/*.log
pkg/
spec/dummy/db/*.sqlite3
spec/dummy/log/*.log
spec/dummy/tmp/
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source :rubygems

gem "rails", "3.0.7"
gem "rake", "~> 0.9.2"
gem "capybara", ">= 0.4.0"

gem "autotest-standalone"
gem "rspec-rails"
114 changes: 114 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (= 3.0.7)
mail (~> 2.2.15)
actionpack (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
rack (~> 1.2.1)
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activeresource (3.0.7)
activemodel (= 3.0.7)
activesupport (= 3.0.7)
activesupport (3.0.7)
arel (2.0.10)
autotest-standalone (4.5.5)
builder (2.1.2)
capybara (0.4.1.2)
celerity (>= 0.7.9)
culerity (>= 0.2.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.3)
celerity (0.8.9)
childprocess (0.1.9)
ffi (~> 1.0.6)
culerity (0.2.15)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (1.0.9)
i18n (0.5.0)
json_pure (1.5.1)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
nokogiri (1.4.4)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
rails (3.0.7)
actionmailer (= 3.0.7)
actionpack (= 3.0.7)
activerecord (= 3.0.7)
activeresource (= 3.0.7)
activesupport (= 3.0.7)
bundler (~> 1.0)
railties (= 3.0.7)
railties (3.0.7)
actionpack (= 3.0.7)
activesupport (= 3.0.7)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
rspec-rails (2.6.1)
actionpack (~> 3.0)
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.6.0)
rubyzip (0.9.4)
selenium-webdriver (0.2.1)
childprocess (>= 0.1.7)
ffi (>= 1.0.7)
json_pure
rubyzip
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
autotest-standalone
capybara (>= 0.4.0)
rails (= 3.0.7)
rake (~> 0.9.2)
rspec-rails
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 Kisko Labs.

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.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Carpentry
=========

____________________________________
/ Carpentry – handcrafted prototypes \
\ with ease /
------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||


Installation
------------

Add Carpentry to Gemfile:

gem "carpentry"

Run the generator to create the prototypes folder:

rails generate carpentry:install


Usage
-----

Put your views in app/views/carpentry/prototypes and view them in
browser at /p/path_to_file.

Examples:

| URI Path | File path |
|--------------|----------------------------------------------------|
| /p | app/views/carpentry/prototypes/index.html.erb |
| /p/home | app/views/carpentry/prototypes/home.html.haml |
| /p/posts/new | app/views/carpentry/prototypes/posts/new.html.slim |

All available Rails helpers work nicely. Pure prototyping bliss!


Gotchas
-------

When rendering a partial, you must specify the full path
(e.g. `carpentry/prototypes/posts/form`) unless the partial is in
`app/views/carpentry/prototypes/`.


License
-------

MIT License. Copyright 2011 Kisko Labs.
18 changes: 18 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: UTF-8
require 'rubygems'
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rake'
require 'rake/task'

require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
Bundler::GemHelper.install_tasks

task :default => :spec
11 changes: 11 additions & 0 deletions app/controllers/carpentry/prototypes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Carpentry
class PrototypesController < ApplicationController
before_filter :before_carpentry,
:if => proc { respond_to?(:before_carpentry, true) }

def serve
env["carpentry.prototype"] = true
render "carpentry/prototypes/#{params[:file_path]}"
end
end
end
14 changes: 14 additions & 0 deletions carpentry.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "carpentry/version"

Gem::Specification.new do |s|
s.name = "carpentry"
s.version = Carpentry::VERSION
s.authors = ["Joao Carlos", "Vesa Vänskä", "Matias Korhonen", "Antti Salonen"]
s.email = ["contact@kiskolabs.com"]
s.homepage = "https://github.com/kiskolabs/carpentry"
s.summary = "Protyping engine for Rails."
s.description = "Handcrafted prototypes for Rails."
s.files = Dir["{app,lib,config}/**/*"] + ["Rakefile", "Gemfile", "README.md"]
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rails.application.routes.draw do
namespace "p", :module => :carpentry do
root :to => "prototypes#serve", :file_path => "index"
match "/*file_path" => "prototypes#serve"
end
end
7 changes: 7 additions & 0 deletions lib/carpentry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "carpentry/no_robots_middleware"

module Carpentry
class Engine < ::Rails::Engine
config.app_middleware.use NoRobotsMiddleware
end
end
18 changes: 18 additions & 0 deletions lib/carpentry/no_robots_middleware.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Carpentry
class NoRobotsMiddleware
def initialize(app)
@app = app
end

def call(env)
status, headers, response = @app.call(env)

if env["carpentry.prototype"] && status == 200
no_robots_tag = %{<meta name="robots" content="noindex, nofollow"/>\n}
response.body = response.body.sub("</head>", "#{no_robots_tag}</head>")
end

[status, headers, response]
end
end
end
3 changes: 3 additions & 0 deletions lib/carpentry/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Carpentry
VERSION = "1.0.0"
end
10 changes: 10 additions & 0 deletions lib/generators/carpentry/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Carpentry
module Generators
class InstallGenerator < Rails::Generators::Base
def create_directory_with_gitkeep
empty_directory "app/views/carpentry/prototypes"
create_file "app/views/carpentry/prototypes/.gitkeep"
end
end
end
end
7 changes: 7 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

Dummy::Application.load_tasks
9 changes: 9 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ApplicationController < ActionController::Base
protect_from_forgery

private

def before_carpentry
@notes = "BEFORE CARPENTRY"
end
end
4 changes: 4 additions & 0 deletions spec/dummy/app/controllers/not_a_prototype_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class NotAPrototypeController < ActionController::Base
def show
end
end
2 changes: 2 additions & 0 deletions spec/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
1 change: 1 addition & 0 deletions spec/dummy/app/views/carpentry/prototypes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INDEX FILE
1 change: 1 addition & 0 deletions spec/dummy/app/views/carpentry/prototypes/notes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @notes %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FORM PARTIAL
3 changes: 3 additions & 0 deletions spec/dummy/app/views/carpentry/prototypes/posts/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEW POST FILE

<%= render "carpentry/prototypes/posts/form" %>
1 change: 1 addition & 0 deletions spec/dummy/app/views/carpentry/prototypes/sites.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SITES FILE
14 changes: 14 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>
1 change: 1 addition & 0 deletions spec/dummy/app/views/not_a_prototype/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOT A PROTOTYPE
4 changes: 4 additions & 0 deletions spec/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Dummy::Application
Loading

0 comments on commit ee2c6e3

Please sign in to comment.