knaveofdiamonds-knave-extras 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Roland Swingler
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ = knave-extras
2
+
3
+ Various bits and pieces I find useful on a rails project. Unlikely to be
4
+ of much use to anyone else without modification.
5
+
6
+ == Copyright
7
+
8
+ Copyright (c) 2009 Roland Swingler. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "knave-extras"
8
+ gem.summary = "Various bits and pieces for a rails project"
9
+ gem.email = "roland.swingler@gmail.com"
10
+ gem.homepage = "http://github.com/knaveofdiamonds/knave-extras"
11
+ gem.authors = ["Roland Swingler"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "knave-extras #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,64 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{knave-extras}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Roland Swingler"]
9
+ s.date = %q{2009-07-26}
10
+ s.email = %q{roland.swingler@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "knave-extras.gemspec",
23
+ "lib/knave_extras.rb",
24
+ "rails_generators/model/USAGE",
25
+ "rails_generators/model/model_generator.rb",
26
+ "rails_generators/model/templates/migration.rb",
27
+ "rails_generators/model/templates/model.rb",
28
+ "rails_generators/model/templates/unit_test.rb",
29
+ "rails_generators/scaffold/USAGE",
30
+ "rails_generators/scaffold/scaffold_generator.rb",
31
+ "rails_generators/scaffold/templates/controller.rb",
32
+ "rails_generators/scaffold/templates/functional_test.rb",
33
+ "rails_generators/scaffold/templates/helper.rb",
34
+ "rails_generators/scaffold/templates/helper_test.rb",
35
+ "rails_generators/scaffold/templates/layout.html.erb",
36
+ "rails_generators/scaffold/templates/style.css",
37
+ "rails_generators/scaffold/templates/view_edit.html.erb",
38
+ "rails_generators/scaffold/templates/view_index.html.erb",
39
+ "rails_generators/scaffold/templates/view_new.html.erb",
40
+ "rails_generators/scaffold/templates/view_show.html.erb",
41
+ "test/knave-extras_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+ s.has_rdoc = true
45
+ s.homepage = %q{http://github.com/knaveofdiamonds/knave-extras}
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.2}
49
+ s.summary = %q{Various bits and pieces for a rails project}
50
+ s.test_files = [
51
+ "test/test_helper.rb",
52
+ "test/knave-extras_test.rb"
53
+ ]
54
+
55
+ if s.respond_to? :specification_version then
56
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
57
+ s.specification_version = 3
58
+
59
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
60
+ else
61
+ end
62
+ else
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ module Knave
2
+ end
@@ -0,0 +1,27 @@
1
+ Description:
2
+ Stubs out a new model. Pass the model name, either CamelCased or
3
+ under_scored, and an optional list of attribute pairs as arguments.
4
+
5
+ Attribute pairs are column_name:sql_type arguments specifying the
6
+ model's attributes. Timestamps are added by default, so you don't have to
7
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
8
+
9
+ You don't have to think up every attribute up front, but it helps to
10
+ sketch out a few so you can start working with the model immediately.
11
+
12
+ This generates a model class in app/models, a unit test in test/unit,
13
+ a test fixture in test/fixtures/singular_name.yml, and a migration in
14
+ db/migrate.
15
+
16
+ Examples:
17
+ `./script/generate model account`
18
+
19
+ creates an Account model, test, fixture, and migration:
20
+ Model: app/models/account.rb
21
+ Test: test/unit/account_test.rb
22
+ Fixtures: test/fixtures/accounts.yml
23
+ Migration: db/migrate/XXX_add_accounts.rb
24
+
25
+ `./script/generate model post title:string body:text published:boolean`
26
+
27
+ creates a Post model with a string title, text body, and published flag.
@@ -0,0 +1,44 @@
1
+ class ModelGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_timestamps => false, :skip_migration => false, :skip_blueprint => false
3
+
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions class_name, "#{class_name}Test"
8
+
9
+ # Model, test, and fixture directories.
10
+ m.directory File.join('app/models', class_path)
11
+ m.directory File.join('test/unit', class_path)
12
+
13
+ # Model class, unit test, and fixtures.
14
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
15
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
16
+
17
+ unless options[:skip_migration]
18
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
19
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
20
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
21
+ end
22
+ end
23
+ end
24
+
25
+ def numeric_attributes
26
+ attributes.select {|a| (! a.reference?) && [:integer, :decimal, :float].include?(a.type) }
27
+ end
28
+
29
+ protected
30
+ def banner
31
+ "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
32
+ end
33
+
34
+ def add_options!(opt)
35
+ opt.separator ''
36
+ opt.separator 'Options:'
37
+ opt.on("--skip-timestamps",
38
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
39
+ opt.on("--skip-migration",
40
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
41
+ opt.on("--skip-blueprint",
42
+ "Don't generation a blueprint for this model") { |v| options[:skip_blueprint] = v}
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>, :null => false
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+ end
11
+
12
+ <% attributes.select(&:reference?).each do |attribute| -%>
13
+ add_index :<%= table_name %>, :<%= attribute.name + "_id" %>
14
+ <% end -%>
15
+ end
16
+
17
+ def self.down
18
+ drop_table :<%= table_name %>
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ <% unless options[:skip_timestamps] -%>
3
+ attr_protected :updated_at, :created_at
4
+ attr_readonly :created_at
5
+
6
+ <% end -%>
7
+ # Relationships
8
+ <% attributes.select(&:reference?).each do |attribute| -%>
9
+ belongs_to :<%= attribute.name %>
10
+ <% end -%>
11
+
12
+ # Validations
13
+ validates_presence_of <%= attributes.map {|a| ":" + a.name }.join(", ") %>
14
+ <% unless numeric_attributes.empty? -%>
15
+ validates_numericality_of <%= numeric_attributes.map {|a| ":" + a.name }.join(", ") %>
16
+ <% end -%>
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "something" do
6
+ fail
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views, along with a full test suite. The resource is ready to use as a
4
+ starting point for your RESTful, resource-oriented application.
5
+
6
+ Pass the name of the model (in singular form), either CamelCased or
7
+ under_scored, as the first argument, and an optional list of attribute
8
+ pairs.
9
+
10
+ Attribute pairs are column_name:sql_type arguments specifying the
11
+ model's attributes. Timestamps are added by default, so you don't have to
12
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
13
+
14
+ You don't have to think up every attribute up front, but it helps to
15
+ sketch out a few so you can start working with the resource immediately.
16
+
17
+ For example, 'scaffold post title:string body:text published:boolean'
18
+ gives you a model with those three attributes, a controller that handles
19
+ the create/show/update/destroy, forms to create and edit your posts, and
20
+ an index that lists them all, as well as a map.resources :posts
21
+ declaration in config/routes.rb.
22
+
23
+ If you want to remove all the generated files, run
24
+ 'script/destroy scaffold ModelName'.
25
+
26
+ Examples:
27
+ `./script/generate scaffold post`
28
+ `./script/generate scaffold post title:string body:text published:boolean`
29
+ `./script/generate scaffold purchase order_id:integer amount:decimal`
@@ -0,0 +1,102 @@
1
+ class ScaffoldGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false
3
+
4
+ attr_reader :controller_name,
5
+ :controller_class_path,
6
+ :controller_file_path,
7
+ :controller_class_nesting,
8
+ :controller_class_nesting_depth,
9
+ :controller_class_name,
10
+ :controller_underscore_name,
11
+ :controller_singular_name,
12
+ :controller_plural_name
13
+ alias_method :controller_file_name, :controller_underscore_name
14
+ alias_method :controller_table_name, :controller_plural_name
15
+
16
+ def initialize(runtime_args, runtime_options = {})
17
+ super
18
+
19
+ if @name == @name.pluralize && !options[:force_plural]
20
+ logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
21
+ @name = @name.singularize
22
+ end
23
+
24
+ @controller_name = @name.pluralize
25
+
26
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
27
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
28
+ @controller_singular_name=base_name.singularize
29
+ if @controller_class_nesting.empty?
30
+ @controller_class_name = @controller_class_name_without_nesting
31
+ else
32
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
33
+ end
34
+ end
35
+
36
+ def manifest
37
+ record do |m|
38
+ # Check for class naming collisions.
39
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
40
+ m.class_collisions(class_name)
41
+
42
+ # Controller, helper, views, test and stylesheets directories.
43
+ m.directory(File.join('app/models', class_path))
44
+ m.directory(File.join('app/controllers', controller_class_path))
45
+ m.directory(File.join('app/helpers', controller_class_path))
46
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
47
+ m.directory(File.join('app/views/layouts', controller_class_path))
48
+ m.directory(File.join('test/functional', controller_class_path))
49
+ m.directory(File.join('test/unit', class_path))
50
+ m.directory(File.join('test/unit/helpers', class_path))
51
+ m.directory(File.join('public/stylesheets', class_path))
52
+
53
+ for action in scaffold_views
54
+ m.template(
55
+ "view_#{action}.html.erb",
56
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
57
+ )
58
+ end
59
+
60
+ # Layout and stylesheet.
61
+ m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
62
+ m.template('style.css', 'public/stylesheets/scaffold.css')
63
+
64
+ m.template(
65
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
66
+ )
67
+
68
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
69
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
70
+ m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
71
+
72
+ m.route_resources controller_file_name
73
+
74
+ m.dependency 'model', [name] + @args, :collision => :skip
75
+ end
76
+ end
77
+
78
+ protected
79
+ # Override with your own usage banner.
80
+ def banner
81
+ "Usage: #{$0} scaffold ModelName [field:type, field:type]"
82
+ end
83
+
84
+ def add_options!(opt)
85
+ opt.separator ''
86
+ opt.separator 'Options:'
87
+ opt.on("--skip-timestamps",
88
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
89
+ opt.on("--skip-migration",
90
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
91
+ opt.on("--force-plural",
92
+ "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v }
93
+ end
94
+
95
+ def scaffold_views
96
+ %w[ index show new edit ]
97
+ end
98
+
99
+ def model_name
100
+ class_name.demodulize
101
+ end
102
+ end
@@ -0,0 +1,72 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ def index
3
+ @<%= table_name %> = <%= class_name %>.all
4
+
5
+ respond_to do |format|
6
+ format.html # index.html.erb
7
+ format.xml { render :xml => @<%= table_name %> }
8
+ end
9
+ end
10
+
11
+ def show
12
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
13
+
14
+ respond_to do |format|
15
+ format.html # show.html.erb
16
+ format.xml { render :xml => @<%= file_name %> }
17
+ end
18
+ end
19
+
20
+ def new
21
+ @<%= file_name %> = <%= class_name %>.new
22
+
23
+ respond_to do |format|
24
+ format.html # new.html.erb
25
+ format.xml { render :xml => @<%= file_name %> }
26
+ end
27
+ end
28
+
29
+ def edit
30
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
31
+ end
32
+
33
+ def create
34
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
35
+
36
+ respond_to do |format|
37
+ if @<%= file_name %>.save
38
+ flash[:notice] = '<%= class_name %> was successfully created.'
39
+ format.html { redirect_to(@<%= table_name %>_url) }
40
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
41
+ else
42
+ format.html { render :action => "new" }
43
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
44
+ end
45
+ end
46
+ end
47
+
48
+ def update
49
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
50
+
51
+ respond_to do |format|
52
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
53
+ flash[:notice] = '<%= class_name %> was successfully updated.'
54
+ format.html { redirect_to(@<%= table_name %>_url) }
55
+ format.xml { head :ok }
56
+ else
57
+ format.html { render :action => "edit" }
58
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
59
+ end
60
+ end
61
+ end
62
+
63
+ def destroy
64
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
65
+ @<%= file_name %>.destroy
66
+
67
+ respond_to do |format|
68
+ format.html { redirect_to(<%= table_name %>_url) }
69
+ format.xml { head :ok }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ super
7
+ @<%= file_name %> = <%= class_name %>.make
8
+ end
9
+
10
+ test "GET /<%= table_name %>" do
11
+ get :index
12
+ assert_not_nil assigns(:<%= table_name %>)
13
+ assert_response :success
14
+ end
15
+
16
+ test "GET /<%= table_name %>/new" do
17
+ get :new
18
+ assert_not_nil assigns(:<%= file_name %>)
19
+ assert_response :success
20
+ end
21
+
22
+ test "GET /<%= table_name %>/:id should show <%= file_name %>" do
23
+ get :show, :id => @<%= file_name %>.to_param
24
+ assert_response :success
25
+ end
26
+
27
+ test "GET /<%= table_name %>/:id/edit" do
28
+ get :edit, :id => @<%= file_name %>.to_param
29
+ assert_not_nil assigns(:<%= file_name %>)
30
+ assert_response :success
31
+ end
32
+
33
+ test "POST /<%= table_name %> should create <%= file_name %>" do
34
+ assert_difference('<%= class_name %>.count') do
35
+ post :create, :<%= file_name %> => { }
36
+ end
37
+ assert_redirected_to <%= table_name %>_path
38
+ end
39
+
40
+ test "PUT /<%= table_name %>/:id should update <%= file_name %>" do
41
+ put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => { }
42
+ assert_redirected_to <%= table_name %>_path
43
+ end
44
+
45
+ test "DELETE /<%= table_name %>/:id should remove <%= file_name %>" do
46
+ assert_difference('<%= class_name %>.count', -1) do
47
+ delete :destroy, :id => @<%= file_name %>.to_param
48
+ end
49
+ assert_redirected_to <%= table_name %>_path
50
+ end
51
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title><%= controller_class_name %>: <%%= controller.action_name %></title>
8
+ <%%= stylesheet_link_tag 'scaffold' %>
9
+ </head>
10
+ <body>
11
+
12
+ <p style="color: green"><%%= flash[:notice] %></p>
13
+
14
+ <%%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,16 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <div class="fmElem">
8
+ <%%= f.label :<%= attribute.name %> %>
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </div>
11
+ <% end -%>
12
+ <div class="controls">
13
+ <%%= f.submit 'Create' %>
14
+ <%%= link_to 'Cancel', <%= plural_name %>_path %>
15
+ </div>
16
+ <%% end %>
@@ -0,0 +1,24 @@
1
+ <h1>Listing <%= plural_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% for attribute in attributes -%>
6
+ <th><%= attribute.column.human_name %></th>
7
+ <% end -%>
8
+ </tr>
9
+
10
+ <%% @<%= plural_name %>.each do |<%= singular_name %>| %>
11
+ <tr>
12
+ <% for attribute in attributes -%>
13
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
14
+ <% end -%>
15
+ <td><%%= link_to 'Show', <%= singular_name %> %></td>
16
+ <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
17
+ <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
18
+ </tr>
19
+ <%% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,16 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <div class="fmElem">
8
+ <%%= f.label :<%= attribute.name %> %>
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </div>
11
+ <% end -%>
12
+ <div class="controls">
13
+ <%%= f.submit 'Create' %>
14
+ <%%= link_to 'Cancel', <%= plural_name %>_path %>
15
+ </div>
16
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %>:</b>
4
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class KnaveExtrasTest < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'knave-extras'
7
+
8
+ class Test::Unit::TestCase
9
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knaveofdiamonds-knave-extras
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roland Swingler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: roland.swingler@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - knave-extras.gemspec
33
+ - lib/knave_extras.rb
34
+ - rails_generators/model/USAGE
35
+ - rails_generators/model/model_generator.rb
36
+ - rails_generators/model/templates/migration.rb
37
+ - rails_generators/model/templates/model.rb
38
+ - rails_generators/model/templates/unit_test.rb
39
+ - rails_generators/scaffold/USAGE
40
+ - rails_generators/scaffold/scaffold_generator.rb
41
+ - rails_generators/scaffold/templates/controller.rb
42
+ - rails_generators/scaffold/templates/functional_test.rb
43
+ - rails_generators/scaffold/templates/helper.rb
44
+ - rails_generators/scaffold/templates/helper_test.rb
45
+ - rails_generators/scaffold/templates/layout.html.erb
46
+ - rails_generators/scaffold/templates/style.css
47
+ - rails_generators/scaffold/templates/view_edit.html.erb
48
+ - rails_generators/scaffold/templates/view_index.html.erb
49
+ - rails_generators/scaffold/templates/view_new.html.erb
50
+ - rails_generators/scaffold/templates/view_show.html.erb
51
+ - test/knave-extras_test.rb
52
+ - test/test_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/knaveofdiamonds/knave-extras
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.2.0
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Various bits and pieces for a rails project
79
+ test_files:
80
+ - test/test_helper.rb
81
+ - test/knave-extras_test.rb