ohlala_rails_scaffold_templates 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ohlala_rails_scaffold_templates.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ Description:
2
+ Installs customized and customizable scaffold templates in your Rails app
3
+
4
+ Example:
5
+ rails generate templates
6
+ This will copy the templates in lib/templates/
@@ -0,0 +1,17 @@
1
+ class OhlalaTemplatesGenerator < Rails::Generators::Base
2
+
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def install
6
+ copy_file "index.html.erb", "lib/templates/erb/scaffold/index.html.erb"
7
+ copy_file "show.html.erb", "lib/templates/erb/scaffold/show.html.erb"
8
+ copy_file "new.html.erb", "lib/templates/erb/scaffold/new.html.erb"
9
+ copy_file "edit.html.erb", "lib/templates/erb/scaffold/edit.html.erb"
10
+ copy_file "_form.html.erb", "lib/templates/erb/scaffold/_form.html.erb"
11
+ copy_file "model.rb", "lib/templates/active_record/model/model.rb"
12
+ copy_file "controller.rb", "lib/templates/rails/scaffold_controller/controller.rb"
13
+ copy_file "unit_test.rb", "lib/templates/test_unit/scaffold/test_unit.rb"
14
+ copy_file "functional_test.rb", "lib/templates/test_unit/scaffold/functional.rb"
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ <%%= simple_form_for @<%= singular_name %> do |f| %>
2
+
3
+ <%%= f.error_notification %>
4
+
5
+ <div class="inputs">
6
+ <%- attributes.each do |attribute| -%>
7
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>,
8
+ :placeholder => 'helpful_short_hint',
9
+ :hint => 'longer_and_very_helpful_hint' %>
10
+ <%- end -%>
11
+ </div>
12
+
13
+ <div class="actions">
14
+ <%%= f.button :submit %>
15
+ </div>
16
+
17
+ <%% end %>
@@ -0,0 +1,55 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+
3
+ before_filter :authenticate, :except => 'show'
4
+ before_filter :authorize, :except => 'show'
5
+
6
+ def index
7
+ # can't replace 'all' by 'by_recent' automatically. It has to be done by hand
8
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>.paginate :page => params[:page], :per_page => 50
9
+ build_admin_menu 1 # calls default admin menu. change admin menu id later
10
+ switch_layout 'admin'
11
+ end
12
+
13
+ def show
14
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
15
+ end
16
+
17
+ def new
18
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
19
+ build_admin_menu 1 # calls default admin menu. change admin menu id later
20
+ switch_layout 'admin'
21
+ end
22
+
23
+ def edit
24
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
25
+ build_admin_menu 1 # calls default admin menu. change admin menu id later
26
+ switch_layout 'admin'
27
+ end
28
+
29
+ def create
30
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
31
+ if @<%= orm_instance.save %>
32
+ redirect_to @<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.'
33
+ else
34
+ render :action => "new", :warning => 'There was a problem saving the <%= human_name %>.'
35
+ switch_layout 'admin'
36
+ end
37
+ end
38
+
39
+ def update
40
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
41
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
42
+ redirect_to @<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.'
43
+ else
44
+ render :action => "edit", :warning => 'There was a problem saving the <%= human_name %>.'
45
+ switch_layout 'admin'
46
+ end
47
+ end
48
+
49
+ def destroy
50
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
51
+ @<%= orm_instance.destroy %>
52
+ redirect_to <%= index_helper %>_path
53
+ end
54
+
55
+ end
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ setup do
6
+ @<%= singular_table_name %> = Factory.create :<%= singular_table_name %>
7
+ @current_user = Factory.create :user, :id => 1, :email => 'test@example.com', :password => 'password', :admin => true
8
+ session[:user_id] = 1
9
+ end
10
+
11
+ test "should get index" do
12
+ a = Factory.create :admin_menu, :id => 1 # using default admin menu. change this value later
13
+ get :index, {:locale => 'en'}
14
+ assert_response :success
15
+ assert_not_nil assigns(:<%= table_name %>)
16
+ end
17
+
18
+ test "should get new" do
19
+ a = Factory.create :admin_menu, :id => 1 # using default admin menu. change this value later
20
+ get :new, {:locale => 'en'}
21
+ assert_response :success
22
+ end
23
+
24
+ test "should create <%= singular_table_name %>" do
25
+ assert_difference('<%= class_name %>.count') do
26
+ post :create, {:<%= singular_table_name %> => @<%= singular_table_name %>.attributes, :locale => 'en'}
27
+ end
28
+ assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
29
+ end
30
+
31
+ test "should show <%= singular_table_name %>" do
32
+ get :show, {:id => @<%= singular_table_name %>.to_param, :locale => 'en'}
33
+ assert_response :success
34
+ end
35
+
36
+ test "should get edit" do
37
+ a = Factory.create :admin_menu, :id => 1 # using default admin menu. change this value later
38
+ get :edit, {:id => @<%= singular_table_name %>.to_param, :locale => 'en'}
39
+ assert_response :success
40
+ end
41
+
42
+ test "should update <%= singular_table_name %>" do
43
+ put :update, {:id => @<%= singular_table_name %>.to_param, :<%= singular_table_name %> => @<%= singular_table_name %>.attributes, :locale => 'en'}
44
+ assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
45
+ end
46
+
47
+ test "should destroy <%= singular_table_name %>" do
48
+ assert_difference('<%= class_name %>.count', -1) do
49
+ delete :destroy, {:id => @<%= singular_table_name %>.to_param, :locale => 'en'}
50
+ end
51
+ assert_redirected_to <%= index_helper %>_path
52
+ end
53
+
54
+ end
@@ -0,0 +1,25 @@
1
+ <%%= will_paginate @<%= plural_table_name %> %>
2
+
3
+ <table>
4
+
5
+ <tr>
6
+ <% for attribute in attributes -%>
7
+ <th><%= attribute.human_name %></th>
8
+ <% end -%>
9
+ <th>Actions</th>
10
+ </tr>
11
+
12
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
13
+ <tr>
14
+ <% for attribute in attributes -%>
15
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
16
+ <% end -%>
17
+ <td><nobr><%%= link_to 'View', <%= singular_table_name %>, :class => 'css3b-left pill button' %><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), :class => 'middle pill button' %><%%= link_to 'Delete', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'css3b-right negative pill button' %></nobr></td>
18
+ </tr>
19
+ <%% end %>
20
+
21
+ <tr><td colspan="3"><%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path, :class => 'pill button' %></td></tr>
22
+
23
+ </table>
24
+
25
+ <%%= will_paginate @<%= plural_table_name %> %>
@@ -0,0 +1,14 @@
1
+ class <%= class_name %> < <%= parent_class_name.classify %>
2
+
3
+ <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
4
+ belongs_to :<%= attribute.name %>
5
+ <% end -%>
6
+ # use the stringex gem to create slug | usually on the title or name attribute
7
+ acts_as_url :name, :url_attribute => :slug, :only_when_blank => true
8
+ def to_param
9
+ "#{id}-#{name.to_url}"
10
+ end
11
+
12
+ scope :by_recent, :order => 'id desc'
13
+
14
+ end
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,11 @@
1
+ <%% set_title @<%= singular_table_name %>.title_or_name_goes_here %>
2
+ <%% set_description @<%= singular_table_name %>.description_field_goes_here %>
3
+
4
+ <h1><%%= @<%= singular_table_name %>.name_or_title_field %></h1>
5
+
6
+ <%%= raw @<%= singular_table_name %>.body_or_main_text_field %>
7
+
8
+ <%% if current_user && current_user.admin? %>
9
+ <hr>
10
+ <p><nobr><%%= link_to 'Edit this <%= singular_table_name %>', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => 'css3b-left pill button' %><%%= link_to 'List all <%= plural_table_name %>', <%= plural_table_name %>_path, :class => 'css3b-right pill button' %></nobr></p>
11
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ # template unit_test.rb under /lib/templates/test_unit/scaffold/
4
+
5
+ class <%= class_name %>Test < ActiveSupport::TestCase
6
+ # Replace this with your real tests.
7
+ test "the truth" do
8
+ assert true
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module OhlalaRailsScaffoldTemplates
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,3 @@
1
+ module OhlalaRailsScaffoldTemplates
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ohlala_rails_scaffold_templates/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ohlala_rails_scaffold_templates"
7
+ s.version = OhlalaRailsScaffoldTemplates::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Swami Atma"]
10
+ s.email = ["swami@ohlalaweb.com"]
11
+ s.homepage = "https://github.com/allesklar/ohlala-rails-scaffold-templates"
12
+ s.summary = %q{Rails 3+ scaffold templates}
13
+ s.description = %q{A ridiculously opinionated set of scaffold templates for Rails 3 and later. Meant to be used for the Ohlàlà! Webdesigns projects but can be customized to any Rails developer's workflow.}
14
+
15
+ s.rubyforge_project = "ohlala_rails_scaffold_templates"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohlala_rails_scaffold_templates
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Swami Atma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-27 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: "A ridiculously opinionated set of scaffold templates for Rails 3 and later. Meant to be used for the Ohl\xC3\xA0l\xC3\xA0! Webdesigns projects but can be customized to any Rails developer's workflow."
17
+ email:
18
+ - swami@ohlalaweb.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - Gemfile
28
+ - Rakefile
29
+ - lib/generators/ohlala_templates/USAGE
30
+ - lib/generators/ohlala_templates/ohlala_templates_generator.rb
31
+ - lib/generators/ohlala_templates/templates/.DS_Store
32
+ - lib/generators/ohlala_templates/templates/_form.html.erb
33
+ - lib/generators/ohlala_templates/templates/controller.rb
34
+ - lib/generators/ohlala_templates/templates/edit.html.erb
35
+ - lib/generators/ohlala_templates/templates/functional_test.rb
36
+ - lib/generators/ohlala_templates/templates/index.html.erb
37
+ - lib/generators/ohlala_templates/templates/model.rb
38
+ - lib/generators/ohlala_templates/templates/new.html.erb
39
+ - lib/generators/ohlala_templates/templates/show.html.erb
40
+ - lib/generators/ohlala_templates/templates/unit_test.rb
41
+ - lib/ohlala_rails_scaffold_templates.rb
42
+ - lib/ohlala_rails_scaffold_templates/version.rb
43
+ - ohlala_rails_scaffold_templates.gemspec
44
+ homepage: https://github.com/allesklar/ohlala-rails-scaffold-templates
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: ohlala_rails_scaffold_templates
67
+ rubygems_version: 1.7.2
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Rails 3+ scaffold templates
71
+ test_files: []
72
+