simply_stored_scaffold 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Vincenzo Rivello
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.
@@ -0,0 +1,41 @@
1
+ = simply_stored_scaffold
2
+
3
+ This is a simple scaffold generator for Rails developer who uses CouchDB with couchrest, couch_potato and simply_stored.
4
+ At the moment only Rails 2.3.x is supported. Rails 3.0 support will come soon(tm)
5
+
6
+ == Installation
7
+
8
+ gem install simply_stored_scaffold
9
+
10
+ == Configuration
11
+
12
+ Once you install the gem, the generators will be available to all Rails applications on your system.
13
+
14
+ == Simple usage
15
+
16
+ Pass the name of the model, either CamelCased or under_scored, as the first
17
+ argument along with an optional list of attribute pairs and controller actions.
18
+
19
+ script/generate simply_stored_scaffold Model column_name:type
20
+
21
+ Will create a controller called "posts" it will contain all seven
22
+ CRUD actions along with the views. A model will be created with the attributes inside
23
+
24
+ script/generate simply_storedd_scaffold post name:string content:text
25
+
26
+ Will create a Post model with with the name and content
27
+ properties with all seven CRUD action
28
+
29
+ == Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so I don't break it in a
34
+ future version unintentionally.
35
+ * Commit, do not mess with rakefile, version, or history.
36
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
37
+ * Send me a pull request. Bonus points for topic branches.
38
+
39
+ == Copyright
40
+
41
+ Copyright (c) 2010 Vincenzo Rivello. See LICENSE for details.
@@ -0,0 +1,25 @@
1
+ Feature: Simply stored scaffold
2
+ In order to scaffold a resource
3
+ As a normal developer
4
+ I want to generate model,controller and views to make rails work in rails 2.3.8
5
+
6
+ Scenario: generate a scaffold for couchdb
7
+ Given a new Rails app
8
+ When I run "script/generate simply_stored_scaffold book title:string description:text published:boolean"
9
+ Then I should see the following files
10
+ | app/models/book.rb |
11
+ | app/controllers/books_controller.rb |
12
+ | app/views/books/index.html.erb |
13
+ | app/views/books/edit.html.erb |
14
+ | app/views/books/_form.html.erb |
15
+ | app/views/books/new.html.erb |
16
+ | app/views/books/show.html.erb |
17
+ And I should see "map.resources :books" in file "config/routes.rb"
18
+ And I should see "property :title , :type => String" in file "app/models/book.rb"
19
+ And I should see "property :description" in file "app/models/book.rb"
20
+ And I should see "property :published , :type => :boolean" in file "app/models/book.rb"
21
+
22
+
23
+
24
+
25
+
@@ -0,0 +1,37 @@
1
+ When /^I run "([^\"]*)"$/ do |command|
2
+ system("cd #{@current_directory} && #{command}")
3
+ end
4
+
5
+ When /^I add "([^\"]*)" to file "([^\"]*)"$/ do |content, short_path|
6
+ path = File.join(@current_directory, short_path)
7
+ File.should exist(path)
8
+ File.open(path, 'a') { |f| f.write(content) }
9
+ end
10
+
11
+ Then /^I should see file "([^\"]*)"$/ do |path|
12
+ File.should exist(File.join(@current_directory, path))
13
+ end
14
+
15
+ Then /^I should see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
16
+ path = File.join(@current_directory, short_path)
17
+ File.should exist(path)
18
+ File.readlines(path).join.should include(content)
19
+ end
20
+
21
+ Then /^I should see the following files$/ do |table|
22
+ table.raw.flatten.each do |path|
23
+ File.should exist(File.join(@current_directory, path))
24
+ end
25
+ end
26
+
27
+ Then /^I should see the following in file "([^\"]*)"$/ do |short_path, table|
28
+ path = File.join(@current_directory, short_path)
29
+ File.should exist(path)
30
+ table.raw.flatten.each do |content|
31
+ File.readlines(path).join.should include(content)
32
+ end
33
+ end
34
+
35
+ Then /^I should successfully run "([^\"]*)"$/ do |command|
36
+ system("cd #{@current_directory} && #{command}").should be_true
37
+ end
@@ -0,0 +1,6 @@
1
+ Given /^a new Rails app$/ do
2
+ FileUtils.mkdir_p("tmp")
3
+ system("rails tmp/rails_app").should be_true
4
+ system("ln -s ../../../rails_generators tmp/rails_app/lib/generators").should be_true
5
+ @current_directory = File.expand_path("tmp/rails_app")
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'cucumber'
2
+ require 'spec'
3
+
4
+ Before do
5
+ FileUtils.rm_rf "tmp/rails_app"
6
+ end
@@ -0,0 +1,7 @@
1
+ Spec::Matchers.define :exist do |path|
2
+ match do
3
+ File.exist?(path)
4
+ end
5
+ failure_message_for_should { "Expected #{path} to exist but no file found" }
6
+ failure_message_for_should_not { "Expected #{path} to not exist but file was found" }
7
+ end
@@ -0,0 +1,19 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views in a RESTful style for simply_stored ORM adapter.
4
+
5
+ Usage:
6
+ Pass the name of the model, either CamelCased or under_scored, as the first
7
+ argument along with an optional list of attribute pairs and controller actions.
8
+
9
+ Examples:
10
+ script/generate simply_stored_scaffold post
11
+
12
+ Will create a controller called "posts" it will contain all seven
13
+ CRUD actions along with the views. A model will be created with the attributes
14
+ inside
15
+
16
+ script/generate simply_storedd_scaffold post name:string content:text
17
+
18
+ Will create a Post model with with the name and content
19
+ properties with all seven CRUD action
@@ -0,0 +1,73 @@
1
+ class SimplyStoredScaffoldGenerator < Rails::Generator::Base
2
+ attr_accessor :name, :attributes
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ usage if @args.empty?
7
+
8
+ @name = @args.first
9
+ @attributes = []
10
+
11
+ @args[1..-1].each do |arg|
12
+ if arg.include?(":")
13
+ @attributes << [ arg.split(":")[0] , arg.split(":")[1] ]
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ def manifest
20
+ record do |m|
21
+ m.template('controller.rb', "app/controllers/#{name.downcase.pluralize}_controller.rb")
22
+ m.template('helper.rb',"app/helpers/#{name.downcase}_helper.rb" )
23
+ m.template('model.rb',"app/models/#{name.downcase}.rb")
24
+ m.directory("app/views/#{name.downcase.pluralize}")
25
+ m.template('views/index.html.erb',"app/views/#{name.downcase.pluralize}/index.html.erb")
26
+ m.template('views/new.html.erb',"app/views/#{name.downcase.pluralize}/new.html.erb")
27
+ m.template('views/edit.html.erb',"app/views/#{name.downcase.pluralize}/edit.html.erb")
28
+ m.template('views/_form.html.erb',"app/views/#{name.downcase.pluralize}/_form.html.erb")
29
+ m.template("views/show.html.erb", "app/views/#{name.downcase.pluralize}/show.html.erb")
30
+ m.route_resources name.downcase.pluralize
31
+ end
32
+ end
33
+
34
+ def render_partial
35
+ "<%= render :partial => 'form' %>"
36
+ end
37
+
38
+ #
39
+ # => find the type to insert in the model for the fields. Need a little bit more of love, seeing that right now the only types
40
+ # => parsed correctly are boolean, time and datetime, but i could be wrong.
41
+ #
42
+
43
+ def typize(type)
44
+ case type
45
+ when "boolean" then ", :type => :#{type.downcase}"
46
+ when "time","datetime","string" then ", :type => #{type.camelize}"
47
+ else
48
+ nil
49
+ end
50
+ end
51
+
52
+
53
+ ##
54
+ ## find_field - actually a copy from the rails generator class.
55
+ ## i needed it here since the Rails::Generator depends from activerecord.
56
+ ##
57
+
58
+ def find_field(type)
59
+ case type
60
+ when "integer", "float", "decimal" then :text_field
61
+ when "time" then :time_select
62
+ when "datetime","timestamp" then :datetime_select
63
+ when "date" then :date_select
64
+ when "string" then :text_field
65
+ when "text" then :text_area
66
+ when "boolean" then :check_box
67
+ else
68
+ :text_field
69
+ end
70
+ end
71
+
72
+
73
+ end
@@ -0,0 +1,59 @@
1
+ class <%= name.camelize.pluralize %>Controller < ApplicationController
2
+
3
+ def index
4
+ @<%= name.downcase.pluralize %> = <%= name.capitalize %>.all
5
+ end
6
+
7
+ def show
8
+ @<%= name.downcase %> = <%= name.capitalize %>.find(params[:id])
9
+ end
10
+
11
+ def new
12
+ @<%= name.downcase %> = <%= name.capitalize %>.new
13
+ end
14
+
15
+ # GET /samples/1/edit
16
+ def edit
17
+ @<%= name.downcase %> = <%= name.capitalize %>.find(params[:id])
18
+ end
19
+
20
+ def create
21
+ @<%= name.downcase %> = <%= name.capitalize %>.new(params[:<%= name.downcase %>])
22
+
23
+ respond_to do |format|
24
+ if @<%= name.downcase %>.save
25
+ format.html { redirect_to(@<%= name.downcase %>, :notice => '<%= name.capitalize %> was successfully created.') }
26
+ format.xml { render :xml => @<%= name.downcase %>, :status => :created, :location => @<%= name.downcase %> }
27
+ else
28
+ format.html { render :action => "new" }
29
+ format.xml { render :xml => @<%= name.downcase %>.errors, :status => :unprocessable_entity }
30
+ end
31
+ end
32
+ end
33
+
34
+ def update
35
+ @<%= name.downcase %> = <%= name.capitalize %>.find(params[:id])
36
+
37
+ respond_to do |format|
38
+ if @<%= name.downcase %>.update_attributes(params[:sample])
39
+ format.html { redirect_to(@<%= name.downcase %>, :notice => '<%= name.capitalize %> was successfully updated.') }
40
+ format.xml { head :ok }
41
+ else
42
+ format.html { render :action => "edit" }
43
+ format.xml { render :xml => @<%= name.downcase %>.errors, :status => :unprocessable_entity }
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ def destroy
50
+ @<%= name.downcase %> = <%= name.capitalize %>.find(params[:id])
51
+ @<%= name.downcase %>.destroy
52
+
53
+ respond_to do |format|
54
+ format.html { redirect_to(<%= name.downcase.pluralize %>_url) }
55
+ format.xml { head :ok }
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,4 @@
1
+ module <%= name.camelize %>Helper
2
+
3
+
4
+ end
@@ -0,0 +1,7 @@
1
+ class <%= name.camelize %>
2
+ include SimplyStored::Couch
3
+
4
+ <%- for attribute in attributes -%>
5
+ property :<%= attribute[0].downcase %> <%= typize(attribute[1]) %>
6
+ <%- end -%>
7
+ end
@@ -0,0 +1,12 @@
1
+ <%% form_for(@<%= name.downcase %>) do |f| %>
2
+ <%%= f.error_messages %>
3
+ <%- for attribute in attributes -%>
4
+ <p>
5
+ <%%= f.label :<%= attribute[0].downcase %> %><br />
6
+ <%%= f.<%= find_field(attribute[1].downcase) %> :<%= attribute[0].downcase %> %>
7
+ </p>
8
+ <%- end -%>
9
+ <p>
10
+ <%%= f.submit 'Create' %>
11
+ </p>
12
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= name.downcase %></h1>
2
+
3
+ <%= render_partial %>
4
+
5
+ <%%= link_to 'Show', @<%= name.downcase %> %> |
6
+ <%%= link_to 'Back', <%= name.downcase.pluralize %>_path %>
@@ -0,0 +1,24 @@
1
+ <h1>Listing <%= name.downcase.pluralize %></h1>
2
+
3
+ <table>
4
+ <%- for attribute in attributes -%>
5
+ <th><%= attribute[0].titleize %></th>
6
+ <%- end -%>
7
+ <tr>
8
+ </tr>
9
+
10
+ <%% @<%= name.downcase.pluralize %>.each do |<%= name.downcase %>| %>
11
+ <tr>
12
+ <%- for attribute in attributes -%>
13
+ <td><%%=h <%= name.downcase%>.<%= attribute[0].downcase %> %></td>
14
+ <%- end -%>
15
+ <td><%%= link_to 'Show', <%= name.downcase %> %></td>
16
+ <td><%%= link_to 'Edit', edit_<%= name.downcase %>_path(<%= name.downcase %>) %></td>
17
+ <td><%%= link_to 'Destroy', <%= name.downcase %> , :confirm => 'Are you sure?', :method => :delete %></td>
18
+ </tr>
19
+ <%% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%%= link_to 'New <%= name.downcase %>', new_<%= name.downcase %>_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= name.downcase %></h1>
2
+
3
+ <%= render_partial %>
4
+
5
+ <%%= link_to 'Back', <%= name.downcase.pluralize %>_path %>
@@ -0,0 +1,9 @@
1
+ <%- for attribute in attributes -%>
2
+ <p>
3
+ <strong><%= attribute[0].titleize %>:</strong>
4
+ <%%=h @<%= name.downcase %>.<%= attribute[0].downcase %> %>
5
+ </p>
6
+ <%- end -%>
7
+
8
+ <%%= link_to 'Edit', edit_<%= name.downcase %>_path(@<%= name.downcase %>) %> |
9
+ <%%= link_to 'Back', <%= name.downcase.pluralize %>_path %>
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simply_stored_scaffold
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Vincenzo Rivello
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-02 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: couchrest
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 65
44
+ segments:
45
+ - 0
46
+ - 37
47
+ version: "0.37"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: couch_potato
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 19
59
+ segments:
60
+ - 0
61
+ - 3
62
+ - 0
63
+ version: 0.3.0
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: simply_stored
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 31
75
+ segments:
76
+ - 0
77
+ - 3
78
+ - 6
79
+ version: 0.3.6
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ description: A simple scaffold generator for Couchrest + couch_potato + simply_stored combo interface for Rails to CouchDB
83
+ email: vincenzo.rivello@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.rdoc
91
+ files:
92
+ - rails_generators/simply_stored_scaffold/USAGE
93
+ - rails_generators/simply_stored_scaffold/simply_stored_scaffold_generator.rb
94
+ - rails_generators/simply_stored_scaffold/templates/controller.rb
95
+ - rails_generators/simply_stored_scaffold/templates/helper.rb
96
+ - rails_generators/simply_stored_scaffold/templates/model.rb
97
+ - rails_generators/simply_stored_scaffold/templates/views/_form.html.erb
98
+ - rails_generators/simply_stored_scaffold/templates/views/edit.html.erb
99
+ - rails_generators/simply_stored_scaffold/templates/views/index.html.erb
100
+ - rails_generators/simply_stored_scaffold/templates/views/new.html.erb
101
+ - rails_generators/simply_stored_scaffold/templates/views/show.html.erb
102
+ - LICENSE
103
+ - README.rdoc
104
+ - features/simply_stored_scaffold.feature
105
+ - features/step_definitions/common_steps.rb
106
+ - features/step_definitions/rails_setup_steps.rb
107
+ - features/support/env.rb
108
+ - features/support/matchers.rb
109
+ has_rdoc: true
110
+ homepage: http://github.com/enzor/simply_stored_scaffold
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options:
115
+ - --charset=UTF-8
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.3.7
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: A simple scaffold generator for simply_stored
143
+ test_files:
144
+ - features/simply_stored_scaffold.feature
145
+ - features/step_definitions/common_steps.rb
146
+ - features/step_definitions/rails_setup_steps.rb
147
+ - features/support/env.rb
148
+ - features/support/matchers.rb