stage 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +38 -0
  4. data/README.txt +48 -0
  5. data/Rakefile +4 -0
  6. data/config/hoe.rb +70 -0
  7. data/config/requirements.rb +15 -0
  8. data/lib/stage.rb +6 -0
  9. data/lib/stage/version.rb +9 -0
  10. data/log/debug.log +0 -0
  11. data/merb_generators/stage/USAGE +5 -0
  12. data/merb_generators/stage/stage_generator.rb +72 -0
  13. data/merb_generators/stage/templates/app/controllers/%controller_file_name%.rb +66 -0
  14. data/merb_generators/stage/templates/app/helpers/%controller_file_name%_helper.rb +25 -0
  15. data/merb_generators/stage/templates/app/models/%resource_name%.rb +5 -0
  16. data/merb_generators/stage/templates/app/views/%controller_file_name%/_data.html.erb +7 -0
  17. data/merb_generators/stage/templates/app/views/%controller_file_name%/_form.html.erb +12 -0
  18. data/merb_generators/stage/templates/app/views/%controller_file_name%/edit.html.erb +7 -0
  19. data/merb_generators/stage/templates/app/views/%controller_file_name%/index.html.erb +24 -0
  20. data/merb_generators/stage/templates/app/views/%controller_file_name%/new.html.erb +6 -0
  21. data/merb_generators/stage/templates/app/views/%controller_file_name%/show.html.erb +4 -0
  22. data/script/console +10 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/script/txt2html +74 -0
  26. data/setup.rb +1585 -0
  27. data/tasks/deployment.rake +34 -0
  28. data/tasks/environment.rake +7 -0
  29. data/tasks/website.rake +17 -0
  30. data/test/test_generator_helper.rb +20 -0
  31. data/test/test_helper.rb +2 -0
  32. data/test/test_stage.rb +11 -0
  33. data/test/test_stage_generator.rb +43 -0
  34. data/website/index.html +93 -0
  35. data/website/index.txt +39 -0
  36. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  37. data/website/stylesheets/screen.css +138 -0
  38. data/website/template.html.erb +48 -0
  39. metadata +99 -0
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-04-17
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Andrew Stone
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,38 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/stage.rb
9
+ lib/stage/version.rb
10
+ log/debug.log
11
+ merb_generators/stage/USAGE
12
+ merb_generators/stage/stage_generator.rb
13
+ merb_generators/stage/templates/app/controllers/%controller_file_name%.rb
14
+ merb_generators/stage/templates/app/helpers/%controller_file_name%_helper.rb
15
+ merb_generators/stage/templates/app/models/%resource_name%.rb
16
+ merb_generators/stage/templates/app/views/%controller_file_name%/_data.html.erb
17
+ merb_generators/stage/templates/app/views/%controller_file_name%/_form.html.erb
18
+ merb_generators/stage/templates/app/views/%controller_file_name%/edit.html.erb
19
+ merb_generators/stage/templates/app/views/%controller_file_name%/index.html.erb
20
+ merb_generators/stage/templates/app/views/%controller_file_name%/new.html.erb
21
+ merb_generators/stage/templates/app/views/%controller_file_name%/show.html.erb
22
+ script/console
23
+ script/destroy
24
+ script/generate
25
+ script/txt2html
26
+ setup.rb
27
+ tasks/deployment.rake
28
+ tasks/environment.rake
29
+ tasks/website.rake
30
+ test/test_generator_helper.rb
31
+ test/test_helper.rb
32
+ test/test_stage.rb
33
+ test/test_stage_generator.rb
34
+ website/index.html
35
+ website/index.txt
36
+ website/javascripts/rounded_corners_lite.inc.js
37
+ website/stylesheets/screen.css
38
+ website/template.html.erb
@@ -0,0 +1,48 @@
1
+ = stage
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ Stage is a code template generator that utilizes helpers as presenters for a cleaner (designer friendly) view.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,70 @@
1
+ require 'stage/version'
2
+
3
+ AUTHOR = 'Andrew Stone' # can also be an array of Authors
4
+ EMAIL = "andy@stonean.com"
5
+ DESCRIPTION = "Code template generator that utilizes helpers as presenters"
6
+ GEM_NAME = 'stage' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'stage' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "astone"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = YAML.load(`svn info`)['Revision']
34
+ VERS = Stage::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'stage documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ $hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Stage
5
+
6
+ end
@@ -0,0 +1,9 @@
1
+ module Stage #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ Description:
2
+ ./script/generate stage
3
+
4
+ Usage:
5
+
@@ -0,0 +1,72 @@
1
+ class StageGenerator < Merb::GeneratorBase
2
+
3
+ attr_reader :controller_class_name,
4
+ :controller_file_name,
5
+ :controller_base_path,
6
+ :controller_modules,
7
+ :full_controller_const,
8
+ :attributes,
9
+ :resource_name,
10
+ :resource_class_name,
11
+ :resource_title_name,
12
+ :resource_plural_name
13
+
14
+ def initialize(runtime_args, runtime_options = {})
15
+ @base = File.dirname(__FILE__)
16
+ super
17
+ name = runtime_args.shift
18
+ @controller_file_name = name.pluralize.snake_case.gsub("::", "/")
19
+ unless @controller_file_name == File.basename(@controller_file_name)
20
+ @controller_base_path = controller_file_name.split("/")[0..-2].join("/")
21
+ end
22
+
23
+ @controller_modules = name.to_const_string.split("::")[0..-2]
24
+ @controller_class_name = name.to_const_string.split("::").last.pluralize
25
+ @resource_name = name.downcase
26
+ @resource_class_name = @resource_name.to_const_string
27
+ @resource_title_name = name.capitalize.snake_case
28
+ @resource_plural_name = @resource_name.pluralize
29
+
30
+ @full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::")
31
+
32
+ @attributes = Hash[*(args.map{|a| a.split(":") }.flatten)]
33
+ end
34
+
35
+ def manifest
36
+ record do |m|
37
+ @m = m
38
+
39
+ m.directory File.join("app/controllers", controller_base_path) if controller_base_path
40
+ m.directory File.join("app/helpers", controller_base_path) if controller_base_path
41
+
42
+ @assigns = { :controller_modules => controller_modules,
43
+ :controller_class_name => controller_class_name,
44
+ :controller_file_name => controller_file_name,
45
+ :controller_base_path => controller_base_path,
46
+ :full_controller_const => full_controller_const,
47
+ :resource_name => resource_name}
48
+
49
+ copy_dirs
50
+ copy_files
51
+ end
52
+ end
53
+
54
+ protected
55
+
56
+ def banner
57
+ <<-EOS
58
+ Stages a resources. This includes the following:
59
+ DataMapper Model
60
+ Resource Controller
61
+ Resource Views
62
+ Resource Helpers (contains presentation code utilized by View)
63
+
64
+ Example
65
+
66
+ merb-gen stage post title:string content:text created_at:datetime
67
+
68
+ USAGE: #{$0} #{spec.name} name"
69
+ EOS
70
+ end
71
+
72
+ end
@@ -0,0 +1,66 @@
1
+ <% counter = 0 -%>
2
+ <% controller_modules.each_with_index do |mod, i| -%>
3
+ <%= " " * i %>module <%= mod %>
4
+ <% counter = i -%>
5
+ <% end -%>
6
+ <% counter = counter == 0 ? 0 : (counter + 1) -%>
7
+ <%= " " * counter %>class <%= controller_class_name %> < Application
8
+ <%= " " * counter %> before :find_<%= resource_name %>, :only => [:show, :edit, :update, :delete]
9
+
10
+ <%= " " * counter %> def index
11
+ <%= " " * counter %> @<%= resource_plural_name %> = <%= resource_class_name %>.all
12
+ <%= " " * counter %> display @<%= resource_plural_name %>
13
+ <%= " " * counter %> end
14
+
15
+ <%= " " * counter %> def show
16
+ <%= " " * counter %> display @<%= resource_name %>
17
+ <%= " " * counter %> end
18
+
19
+ <%= " " * counter %> def new
20
+ <%= " " * counter %> only_provides :html
21
+ <%= " " * counter %> @<%= resource_name %> = <%= resource_class_name %>.new
22
+ <%= " " * counter %> render
23
+ <%= " " * counter %> end
24
+
25
+ <%= " " * counter %> def edit
26
+ <%= " " * counter %> only_provides :html
27
+ <%= " " * counter %> render
28
+ <%= " " * counter %> end
29
+
30
+ <%= " " * counter %> def create
31
+ <%= " " * counter %> @<%= resource_name %> = <%= resource_class_name %>.new(params[:<%= resource_name %>])
32
+ <%= " " * counter %> if @<%= resource_name %>.save
33
+ <%= " " * counter %> redirect url(:<%= resource_name %>, @<%= resource_name %>)
34
+ <%= " " * counter %> else
35
+ <%= " " * counter %> render :new
36
+ <%= " " * counter %> end
37
+ <%= " " * counter %> end
38
+
39
+ <%= " " * counter %> def update
40
+ <%= " " * counter %> if @<%= resource_name %>.update_attributes(params[:<%= resource_name %>])
41
+ <%= " " * counter %> redirect url(:<%= resource_name %>, @<%= resource_name %>)
42
+ <%= " " * counter %> else
43
+ <%= " " * counter %> raise BadRequest
44
+ <%= " " * counter %> end
45
+ <%= " " * counter %> end
46
+
47
+ <%= " " * counter %> def destroy
48
+ <%= " " * counter %> if @<%= resource_name %>.destroy!
49
+ <%= " " * counter %> redirect url(:<%= resource_name %>)
50
+ <%= " " * counter %> else
51
+ <%= " " * counter %> raise BadRequest
52
+ <%= " " * counter %> end
53
+ <%= " " * counter %> end
54
+
55
+ <%= " " * counter %> private
56
+ <%= " " * counter %> def find_<%= resource_name %>
57
+ <%= " " * counter %> @<%= resource_name %> = <%= resource_class_name %>.first(params[:id])
58
+ <%= " " * counter %> raise NotFound unless @<%= resource_name %>
59
+ <%= " " * counter %> end
60
+
61
+ <%= " " * counter %>end
62
+ <% counter = counter == 0 ? 0 : (counter - 1) -%>
63
+ <% controller_modules.reverse.each_with_index do |mod, i| -%>
64
+ <%= " " * counter %>end # <%= mod %>
65
+ <% counter = counter - 1 -%>
66
+ <% end -%>
@@ -0,0 +1,25 @@
1
+ <% counter = 1 -%>
2
+ module Merb
3
+ <% controller_modules.each_with_index do |mod, i| -%>
4
+ <%= " " * i %>module <%= mod %>
5
+ <% counter = i -%>
6
+ <% end -%>
7
+ <% counter = counter == 0 ? 0 : (counter + 1) -%>
8
+ <%= " " * counter %>module <%= controller_class_name %>Helper
9
+ <% attributes.each do |attr| -%>
10
+ <%= " " * counter %> def <%= resource_name %>_<%= attr.first %>_value
11
+ <%= " " * counter %> if @action_name == "show"
12
+ <%= " " * counter %> @<%= resource_name %>.<%= attr.first %>
13
+ <%= " " * counter %> else
14
+ <%= " " * counter %> text_field :<%= attr.first %>
15
+ <%= " " * counter %> end
16
+ <%= " " * counter %> end
17
+
18
+ <% end -%>
19
+ <%= " " * counter %>end
20
+ <% counter = counter == 0 ? 0 : (counter - 1) -%>
21
+ <% controller_modules.reverse.each_with_index do |mod, i| -%>
22
+ <%= " " * counter %>end # <%= mod %>
23
+ <% counter = counter - 1 -%>
24
+ <% end -%>
25
+ end
@@ -0,0 +1,5 @@
1
+ class <%= resource_class_name %> < DataMapper::Base
2
+ <% attributes.each do |attr| -%>
3
+ <%= "property :#{attr.first}, :#{attr.last}" %>
4
+ <% end -%>
5
+ end
@@ -0,0 +1,7 @@
1
+ <% attributes.each do |attr| -%>
2
+ <p>
3
+ <b><%= attr.first.capitalize %></b><br />
4
+ <%%= <%= resource_name %>_<%= attr.first %>_value %>
5
+ </p>
6
+
7
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <%%
2
+ submit_label = "Update"
3
+ submit_label = "Create" if @<%= resource_name %>.new_record?
4
+ -%>
5
+
6
+ <%%= error_messages_for :<%= resource_name %> %>
7
+
8
+ <%% form_for(:<%= resource_name %>, :action => url(:<%= resource_name %>)) do %>
9
+ <%%= partial :data %>
10
+ <p> <%%= submit_button submit_label %> </p>
11
+ <%% end %>
12
+
@@ -0,0 +1,7 @@
1
+ <h1>Editing <%= resource_title_name %></h1>
2
+
3
+ <%%= partial "form" %>
4
+
5
+ <%%= link_to 'Show', url(:<%= resource_name %>, @<%= resource_name %>) %> |
6
+ <%%= link_to 'Back', url(:<%= resource_plural_name %>) %>
7
+
@@ -0,0 +1,24 @@
1
+ <h1><%= resource_plural_name.capitalize %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% attributes.each do |attr| -%>
6
+ <th><%= attr.first.capitalize %></th>
7
+ <% end -%>
8
+ </tr>
9
+
10
+ <%% for <%= resource_name %> in @<%= resource_plural_name %> %>
11
+ <tr>
12
+ <% attributes.each do |attr| -%>
13
+ <td><%%= <%= resource_name %>.<%= attr.first %> %></td>
14
+ <% end -%>
15
+ <td><%%= link_to 'Show', url(:<%= resource_name %>, <%= resource_name %>) %></td>
16
+ <td><%%= link_to 'Edit', url(:edit_<%= resource_name %>, @<%= resource_name %>) %></td>
17
+ <td><%%= link_to 'Destroy', url(:delete_<%= resource_name %>, @<%= resource_name %>), :confirm => 'Are you sure?', :method => :delete %></td>
18
+ </tr>
19
+ <%% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%%= link_to 'New <%= resource_title_name %>', url(:new_<%= resource_name %>) %>