Skip to content
Browse files

generator in progress

  • Loading branch information...
1 parent 38478c4 commit 6854b0b368df2343544aeeb38141e4ce2a07ab67 @barthezslavik barthezslavik committed Dec 25, 2011
View
55 app/controllers/proposals_controller.rb
@@ -1,83 +1,32 @@
class ProposalsController < ApplicationController
- # GET /proposals
- # GET /proposals.json
+
def index
@proposals = Proposal.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @proposals }
- end
end
- # GET /proposals/1
- # GET /proposals/1.json
def show
@proposal = Proposal.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @proposal }
- end
end
- # GET /proposals/new
- # GET /proposals/new.json
def new
@proposal = Proposal.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @proposal }
- end
end
- # GET /proposals/1/edit
def edit
@proposal = Proposal.find(params[:id])
end
- # POST /proposals
- # POST /proposals.json
def create
@proposal = Proposal.new(params[:proposal])
-
- respond_to do |format|
- if @proposal.save
- format.html { redirect_to @proposal, notice: 'Proposal was successfully created.' }
- format.json { render json: @proposal, status: :created, location: @proposal }
- else
- format.html { render action: "new" }
- format.json { render json: @proposal.errors, status: :unprocessable_entity }
- end
- end
end
- # PUT /proposals/1
- # PUT /proposals/1.json
def update
@proposal = Proposal.find(params[:id])
-
- respond_to do |format|
- if @proposal.update_attributes(params[:proposal])
- format.html { redirect_to @proposal, notice: 'Proposal was successfully updated.' }
- format.json { head :ok }
- else
- format.html { render action: "edit" }
- format.json { render json: @proposal.errors, status: :unprocessable_entity }
- end
- end
end
- # DELETE /proposals/1
- # DELETE /proposals/1.json
def destroy
@proposal = Proposal.find(params[:id])
@proposal.destroy
-
- respond_to do |format|
- format.html { redirect_to proposals_url }
- format.json { head :ok }
- end
end
+
end
View
10 app/views/proposals/_proposal.html.haml
@@ -0,0 +1,10 @@
+%table
+ - @proposal.each do |p|
+ %tr
+ %td
+ %span.span_currentvote
+ %td
+ &nbsp;
+ %td
+ %h3
+ =link_to p.content, "/proposals/#{p.id}"
View
7 app/views/proposals/index.js.haml
@@ -0,0 +1,7 @@
+!= "$('ul.tabbernav').html('#{j render "shared/tabs"}').show();"
+- unless params[:page]
+ != "$('#loop_main').html('#{j render(@proposals)}').append('#{j paginate(@proposals)}');"
+- else
+ != "$('#loop_main').append('#{j render(@proposals)}').append('#{j paginate(@proposals)}');"
+ != if "$(#span.next).length"
+ != "$('.pagination').remove();"
View
3 app/views/users/index.js.haml
@@ -1,2 +1,3 @@
+!= "$('ul.tabbernav').html('#{j render "shared/tabs"}');"
+!= "$('ul.tabbernav').hide();"
!= "$('#loop_main').html('#{j render @users}');"
-!= "$('.tabbernav').hide()"
View
67 lib/generators/ria/ria_generator.rb
@@ -1,46 +1,47 @@
+class String
+ def initial
+ self[0,1]
+ end
+end
+
class RiaGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
- argument :layout_name, :type => :string, :default => "proposal"
- class_option :stylesheet, :type => :boolean, :default => true, :description => "Include stylesheet file"
+ argument :name, :type => :string, :default => "proposal"
+ #class_option :stylesheet, :type => :boolean, :default => true, :description => "Include stylesheet file"
def generate_layout
- copy_file "stylesheet.css", "app/assets/stylesheets/#{file_name}.sass" if options.stylesheet?
- template "layout.html.erb", "app/#{file_name}/views/index.html.haml"
+ template "_model.html.haml", "app/views/#{plural_name}/_#{file_name}.html.haml"
+ template "index.js.haml", "app/views/#{plural_name}/index.js.haml"
+ template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
+ #template "layout.html.erb", "app/#{file_name}/views/index.html.haml"
end
private
def file_name
- layout_name.underscore
+ name.underscore
+ end
+
+ def plural_name
+ name.pluralize
end
- # invoke mongoid
- # create app/models/proposal.rb
- # invoke test_unit
- # create test/unit/proposal_test.rb
- # create test/fixtures/proposals.yml
- # route resources :proposals
- # invoke scaffold_controller
- # create app/controllers/proposals_controller.rb
- # invoke erb
- # create app/views/proposals
- # create app/views/proposals/index.html.erb
- # create app/views/proposals/edit.html.erb
- # create app/views/proposals/show.html.erb
- # create app/views/proposals/new.html.erb
- # create app/views/proposals/_form.html.erb
- # invoke test_unit
- # create test/functional/proposals_controller_test.rb
- # invoke helper
- # create app/helpers/proposals_helper.rb
- # invoke test_unit
- # create test/unit/helpers/proposals_helper_test.rb
- # invoke assets
- # invoke js
- # create app/assets/javascripts/proposals.js
- # invoke scss
- # create app/assets/stylesheets/proposals.css.scss
- # invoke scss
- # identical app/assets/stylesheets/scaffolds.css.scss
+# create app/models/proposal.rb
+# route resources :proposals
+# create app/controllers/proposals_controller.rb
+# create app/views/proposals
+# create app/views/proposals/index.html.erb
+# create app/views/proposals/edit.html.erb
+# create app/views/proposals/show.html.erb
+# create app/views/proposals/new.html.erb
+# create app/views/proposals/_form.html.erb
+# create app/assets/javascripts/proposals.js
end
View
10 lib/generators/ria/templates/_model.html.haml
@@ -0,0 +1,10 @@
+%table
+ - @<%= file_name %>.each do |<%= file_name.initial %>|
+ %tr
+ %td
+ %span.span_currentvote
+ %td
+ &nbsp;
+ %td
+ %h3
+ =link_to <%= file_name.initial %>.content, "/<%=plural_name%>/#{<%=file_name.initial%>.id}"
View
32 lib/generators/ria/templates/controller.rb
@@ -0,0 +1,32 @@
+class <%=plural_name.capitalize%>Controller < ApplicationController
+
+ def index
+ @<%=plural_name%> = <%=file_name.capitalize%>.all
+ end
+
+ def show
+ @<%=plural_name%> = <%=file_name.capitalize%>.find(params[:id])
+ end
+
+ def new
+ @<%=plural_name%> = <%=file_name.capitalize%>.new
+ end
+
+ def edit
+ @<%=plural_name%> = <%=file_name.capitalize%>.find(params[:id])
+ end
+
+ def create
+ @<%=plural_name%> = <%=file_name.capitalize%>.new(params[:proposal])
+ end
+
+ def update
+ @<%=plural_name%> = <%=file_name.capitalize%>.find(params[:id])
+ end
+
+ def destroy
+ @<%=plural_name%> = <%=file_name.capitalize%>.find(params[:id])
+ @<%=plural_name%>.destroy
+ end
+
+end
View
32 lib/generators/ria/templates/controller.rb~
@@ -0,0 +1,32 @@
+class <%=plural_name.capitalize%>Controller < ApplicationController
+
+ def index
+ @proposals = Proposal.all
+ end
+
+ def show
+ @proposal = Proposal.find(params[:id])
+ end
+
+ def new
+ @proposal = Proposal.new
+ end
+
+ def edit
+ @proposal = Proposal.find(params[:id])
+ end
+
+ def create
+ @proposal = Proposal.new(params[:proposal])
+ end
+
+ def update
+ @proposal = Proposal.find(params[:id])
+ end
+
+ def destroy
+ @proposal = Proposal.find(params[:id])
+ @proposal.destroy
+ end
+
+end
View
6 lib/generators/ria/templates/edit.html.haml
@@ -0,0 +1,6 @@
+<h1>Editing proposal</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @proposal %> |
+<%= link_to 'Back', proposals_path %>
View
7 lib/generators/ria/templates/index.js.haml
@@ -0,0 +1,7 @@
+!= "$('ul.tabbernav').html('#{j render "shared/tabs"}').show();"
+- unless params[:page]
+ != "$('#loop_main').html('#{j render(@<%=plural_name%>)}').append('#{j paginate(@<%=plural_name%>)}');"
+- else
+ != "$('#loop_main').append('#{j render(@<%=plural_name%>)}').append('#{j paginate(@<%=plural_name%>)}');"
+ != if "$(#span.next).length"
+ != "$('.pagination').remove();"
View
5 lib/generators/ria/templates/new.html.haml
@@ -0,0 +1,5 @@
+<h1>New proposal</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', proposals_path %>
View
5 lib/generators/ria/templates/show.html.haml
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_proposal_path(@proposal) %> |
+<%= link_to 'Back', proposals_path %>

0 comments on commit 6854b0b

Please sign in to comment.
Something went wrong with that request. Please try again.