thorero-gen 0.9.4

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.
Files changed (152) hide show
  1. data/LICENSE +20 -0
  2. data/README +21 -0
  3. data/Rakefile +65 -0
  4. data/TODO +13 -0
  5. data/bin/merb-gen +10 -0
  6. data/lib/merb-gen.rb +37 -0
  7. data/lib/merb-gen/controller.rb +69 -0
  8. data/lib/merb-gen/freezer.rb +19 -0
  9. data/lib/merb-gen/generator.rb +55 -0
  10. data/lib/merb-gen/helper.rb +53 -0
  11. data/lib/merb-gen/merb.rb +27 -0
  12. data/lib/merb-gen/merb/merb_flat.rb +31 -0
  13. data/lib/merb-gen/merb/merb_full.rb +35 -0
  14. data/lib/merb-gen/merb/merb_very_flat.rb +33 -0
  15. data/lib/merb-gen/merb_plugin.rb +33 -0
  16. data/lib/merb-gen/migration.rb +69 -0
  17. data/lib/merb-gen/model.rb +67 -0
  18. data/lib/merb-gen/part_controller.rb +55 -0
  19. data/lib/merb-gen/resource.rb +32 -0
  20. data/lib/merb-gen/resource_controller.rb +91 -0
  21. data/lib/merb-gen/session_migration.rb +44 -0
  22. data/lib/merb-gen/slice.rb +25 -0
  23. data/lib/merb-gen/slice/full.rb +31 -0
  24. data/lib/merb-gen/slice/thin.rb +31 -0
  25. data/lib/merb-gen/slice/very_thin.rb +31 -0
  26. data/spec/controller_spec.rb +94 -0
  27. data/spec/merb_spec.rb +28 -0
  28. data/spec/migration_spec.rb +47 -0
  29. data/spec/model_spec.rb +95 -0
  30. data/spec/resource_controller_spec.rb +98 -0
  31. data/spec/spec_helper.rb +7 -0
  32. data/templates/application/merb/Rakefile +76 -0
  33. data/templates/application/merb/app/controllers/application.rb +2 -0
  34. data/templates/application/merb/app/controllers/exceptions.rb +13 -0
  35. data/templates/application/merb/app/helpers/global_helpers.rb +5 -0
  36. data/templates/application/merb/app/views/exceptions/internal_server_error.html.erb +216 -0
  37. data/templates/application/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  38. data/templates/application/merb/app/views/exceptions/not_found.html.erb +47 -0
  39. data/templates/application/merb/app/views/layout/application.html.erb +11 -0
  40. data/templates/application/merb/autotest/discover.rb +1 -0
  41. data/templates/application/merb/autotest/merb.rb +149 -0
  42. data/templates/application/merb/autotest/merb_rspec.rb +166 -0
  43. data/templates/application/merb/config/environments/development.rb +7 -0
  44. data/templates/application/merb/config/environments/production.rb +7 -0
  45. data/templates/application/merb/config/environments/rake.rb +7 -0
  46. data/templates/application/merb/config/environments/test.rb +6 -0
  47. data/templates/application/merb/config/init.rb +164 -0
  48. data/templates/application/merb/config/rack.rb +12 -0
  49. data/templates/application/merb/config/router.rb +35 -0
  50. data/templates/application/merb/public/images/merb.jpg +0 -0
  51. data/templates/application/merb/public/merb.fcgi +22 -0
  52. data/templates/application/merb/public/stylesheets/master.css +119 -0
  53. data/templates/application/merb/spec/spec.opts +0 -0
  54. data/templates/application/merb/spec/spec_helper.rb +13 -0
  55. data/templates/application/merb/test/test_helper.rb +14 -0
  56. data/templates/application/merb_flat/README.txt +10 -0
  57. data/templates/application/merb_flat/application.rb +15 -0
  58. data/templates/application/merb_flat/config/framework.rb +7 -0
  59. data/templates/application/merb_flat/config/init.rb +18 -0
  60. data/templates/application/merb_flat/views/foo.html.erb +3 -0
  61. data/templates/application/merb_plugin/LICENSE +20 -0
  62. data/templates/application/merb_plugin/README +4 -0
  63. data/templates/application/merb_plugin/Rakefile +59 -0
  64. data/templates/application/merb_plugin/TODO +5 -0
  65. data/templates/application/merb_plugin/lib/%base_name%.rb +18 -0
  66. data/templates/application/merb_plugin/lib/%base_name%/merbtasks.rb +6 -0
  67. data/templates/application/merb_plugin/spec/%base_name%_spec.rb +7 -0
  68. data/templates/application/merb_plugin/spec/spec_helper.rb +2 -0
  69. data/templates/application/merb_plugin/test/%base_name%_test.rb +0 -0
  70. data/templates/application/merb_plugin/test/test_helper.rb +2 -0
  71. data/templates/application/merb_very_flat/application.rbt +17 -0
  72. data/templates/application/slice/full/LICENSE +20 -0
  73. data/templates/application/slice/full/README +170 -0
  74. data/templates/application/slice/full/Rakefile +48 -0
  75. data/templates/application/slice/full/TODO +15 -0
  76. data/templates/application/slice/full/app/controllers/application.rb +5 -0
  77. data/templates/application/slice/full/app/controllers/main.rb +7 -0
  78. data/templates/application/slice/full/app/helpers/application_helper.rb +64 -0
  79. data/templates/application/slice/full/app/views/layout/%underscored_base_name%.html.erb +16 -0
  80. data/templates/application/slice/full/app/views/main/index.html.erb +1 -0
  81. data/templates/application/slice/full/lib/%base_name%.rb +78 -0
  82. data/templates/application/slice/full/lib/%base_name%/merbtasks.rb +166 -0
  83. data/templates/application/slice/full/lib/%base_name%/slicetasks.rb +18 -0
  84. data/templates/application/slice/full/public/javascripts/master.js +0 -0
  85. data/templates/application/slice/full/public/stylesheets/master.css +2 -0
  86. data/templates/application/slice/full/spec/%base_name%_spec.rb +130 -0
  87. data/templates/application/slice/full/spec/controllers/main_spec.rb +61 -0
  88. data/templates/application/slice/full/spec/spec_helper.rb +44 -0
  89. data/templates/application/slice/full/stubs/app/controllers/application.rb +2 -0
  90. data/templates/application/slice/full/stubs/app/controllers/main.rb +2 -0
  91. data/templates/application/slice/thin/LICENSE +20 -0
  92. data/templates/application/slice/thin/README +130 -0
  93. data/templates/application/slice/thin/Rakefile +46 -0
  94. data/templates/application/slice/thin/TODO +7 -0
  95. data/templates/application/slice/thin/application.rb +36 -0
  96. data/templates/application/slice/thin/lib/%base_name%.rb +93 -0
  97. data/templates/application/slice/thin/lib/%base_name%/merbtasks.rb +106 -0
  98. data/templates/application/slice/thin/lib/%base_name%/slicetasks.rb +18 -0
  99. data/templates/application/slice/thin/public/javascripts/master.js +0 -0
  100. data/templates/application/slice/thin/public/stylesheets/master.css +2 -0
  101. data/templates/application/slice/thin/stubs/application.rb +9 -0
  102. data/templates/application/slice/thin/views/layout/%underscored_base_name%.html.erb +16 -0
  103. data/templates/application/slice/thin/views/main/index.html.erb +1 -0
  104. data/templates/application/slice/very_thin/LICENSE +20 -0
  105. data/templates/application/slice/very_thin/README +110 -0
  106. data/templates/application/slice/very_thin/Rakefile +46 -0
  107. data/templates/application/slice/very_thin/TODO +7 -0
  108. data/templates/application/slice/very_thin/application.rb +36 -0
  109. data/templates/application/slice/very_thin/lib/%base_name%.rb +89 -0
  110. data/templates/application/slice/very_thin/lib/%base_name%/merbtasks.rb +106 -0
  111. data/templates/application/slice/very_thin/lib/%base_name%/slicetasks.rb +18 -0
  112. data/templates/component/controller/app/controllers/%file_name%.rb +11 -0
  113. data/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
  114. data/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
  115. data/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
  116. data/templates/component/freezer/script/frozen_merb +43 -0
  117. data/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
  118. data/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
  119. data/templates/component/migration/activerecord/schema/migrations/%file_name%.rb +19 -0
  120. data/templates/component/migration/datamapper/schema/migrations/%file_name%.rb +7 -0
  121. data/templates/component/migration/sequel/schema/migrations/%file_name%.rb +24 -0
  122. data/templates/component/model/activerecord/app/models/%file_name%.rb +2 -0
  123. data/templates/component/model/datamapper/app/models/%file_name%.rb +6 -0
  124. data/templates/component/model/none/app/models/%file_name%.rb +5 -0
  125. data/templates/component/model/rspec/spec/models/%file_name%_spec.rb +7 -0
  126. data/templates/component/model/sequel/app/models/%file_name%.rb +2 -0
  127. data/templates/component/model/test_unit/test/models/%file_name%_test.rb +9 -0
  128. data/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
  129. data/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
  130. data/templates/component/resource_controller/activerecord/app/controllers/%file_name%.rb +57 -0
  131. data/templates/component/resource_controller/activerecord/app/views/%file_name%/edit.html.erb +3 -0
  132. data/templates/component/resource_controller/activerecord/app/views/%file_name%/index.html.erb +3 -0
  133. data/templates/component/resource_controller/activerecord/app/views/%file_name%/new.html.erb +3 -0
  134. data/templates/component/resource_controller/activerecord/app/views/%file_name%/show.html.erb +3 -0
  135. data/templates/component/resource_controller/datamapper/app/controllers/%file_name%.rb +59 -0
  136. data/templates/component/resource_controller/datamapper/app/views/%file_name%/edit.html.erb +21 -0
  137. data/templates/component/resource_controller/datamapper/app/views/%file_name%/index.html.erb +24 -0
  138. data/templates/component/resource_controller/datamapper/app/views/%file_name%/new.html.erb +20 -0
  139. data/templates/component/resource_controller/datamapper/app/views/%file_name%/show.html.erb +14 -0
  140. data/templates/component/resource_controller/none/app/controllers/%file_name%.rb +36 -0
  141. data/templates/component/resource_controller/none/app/views/%file_name%/edit.html.erb +3 -0
  142. data/templates/component/resource_controller/none/app/views/%file_name%/index.html.erb +3 -0
  143. data/templates/component/resource_controller/none/app/views/%file_name%/new.html.erb +3 -0
  144. data/templates/component/resource_controller/none/app/views/%file_name%/show.html.erb +3 -0
  145. data/templates/component/resource_controller/sequel/app/controllers/%file_name%.rb +59 -0
  146. data/templates/component/resource_controller/sequel/app/views/%file_name%/edit.html.erb +3 -0
  147. data/templates/component/resource_controller/sequel/app/views/%file_name%/index.html.erb +3 -0
  148. data/templates/component/resource_controller/sequel/app/views/%file_name%/new.html.erb +3 -0
  149. data/templates/component/resource_controller/sequel/app/views/%file_name%/show.html.erb +3 -0
  150. data/templates/component/session_migration/activerecord/schema/migrations/%version%_sessions.rb +12 -0
  151. data/templates/component/session_migration/sequel/schema/migrations/%version%_sessions.rb +16 -0
  152. metadata +362 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) <%= Time.now.year %> YOUR NAME
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,170 @@
1
+ <%= module_name %>
2
+ <%= "=" * module_name.size %>
3
+
4
+ A slice for the Merb framework.
5
+
6
+ ------------------------------------------------------------------------------
7
+
8
+ <%= base_name %>
9
+ |-- LICENSE
10
+ |-- README
11
+ |-- Rakefile [1]
12
+ |-- TODO
13
+ |-- app [2]
14
+ | |-- controllers
15
+ | | |-- application.rb
16
+ | | `-- main.rb
17
+ | |-- helpers
18
+ | | `-- application_helper.rb
19
+ | `-- views
20
+ | |-- layout
21
+ | | `-- <%= underscored_name %>.html.erb [3]
22
+ | `-- main
23
+ | `-- index.html.erb
24
+ |-- lib
25
+ | |-- <%= base_name %>
26
+ | | |-- merbtasks.rb [4]
27
+ | | `-- slicetasks.rb [5]
28
+ | `-- <%= base_name %>.rb [6]
29
+ |-- log
30
+ | `-- merb_test.log
31
+ |-- public [7]
32
+ | |-- javascripts
33
+ | | `-- master.js
34
+ | `-- stylesheets
35
+ | `-- master.css
36
+ |-- spec [8]
37
+ | |-- <%= base_name %>_spec.rb
38
+ | |-- controllers
39
+ | | `-- main_spec.rb
40
+ | `-- spec_helper.rb
41
+ `-- stubs [9]
42
+ `-- app
43
+ `-- controllers
44
+ |-- application.rb
45
+ `-- main.rb
46
+
47
+
48
+ 1. Rake tasks to package/install the gem - edit this to modify the manifest.
49
+ 2. The slice application: controllers, models, helpers, views.
50
+ 3. The default layout, as specified in Merb::Slices::config[:<%= underscored_name %>][:layout]
51
+ change this to :application to use the app's layout.
52
+ 4. Standard rake tasks available to your application.
53
+ 5. Your custom application rake tasks.
54
+ 6. The main slice file - contains all slice setup logic/config.
55
+ 7. Public assets you (optionally) install using rake slices:<%= underscored_name %>:install
56
+ 8. Specs for basis slice behaviour - you usually adapt these for your slice.
57
+ 9. Stubs of classes/views/files for the end-user to override - usually these
58
+ mimic the files in app/ and/or public/; use rake slices:<%= underscored_name %>:stubs to
59
+ get started with the override stubs. Also, slices:<%= underscored_name %>:patch will
60
+ copy over views to override in addition to the files found in /stubs.
61
+
62
+
63
+ To see all available tasks for <%= module_name %> run:
64
+
65
+ rake -T slices:<%= underscored_name %>
66
+
67
+ ------------------------------------------------------------------------------
68
+
69
+ Instructions for installation:
70
+
71
+ file: config/init.rb
72
+
73
+ # add the slice as a regular dependency
74
+
75
+ dependency '<%= base_name %>'
76
+
77
+ # if needed, configure which slices to load and in which order
78
+
79
+ Merb::Plugins.config[:merb_slices] = { :queue => ["<%= module_name %>", ...] }
80
+
81
+ # optionally configure the plugins in a before_app_loads callback
82
+
83
+ Merb::BootLoader.before_app_loads do
84
+
85
+ Merb::Slices::config[:<%= underscored_name %>][:option] = value
86
+
87
+ end
88
+
89
+ file: config/router.rb
90
+
91
+ # example: /<%= base_name %>/:controller/:action/:id
92
+
93
+ r.add_slice(:<%= module_name %>)
94
+
95
+ # example: /foo/:controller/:action/:id
96
+
97
+ r.add_slice(:<%= module_name %>, 'foo') # same as :path => 'foo'
98
+
99
+ # example: /:lang/:controller/:action/:id (with :a param set)
100
+
101
+ r.add_slice(:<%= module_name %>, :path => ':lang', :params => { :a => 'b' })
102
+
103
+ # example: /:controller/:action/:id
104
+
105
+ r.slice(:<%= module_name %>)
106
+
107
+ Normally you should also run the following rake task:
108
+
109
+ rake slices:<%= underscored_name %>:install
110
+
111
+ ------------------------------------------------------------------------------
112
+
113
+ You can put your application-level overrides in:
114
+
115
+ host-app/slices/<%= base_name %>/app - controllers, models, views ...
116
+
117
+ Templates are located in this order:
118
+
119
+ 1. host-app/slices/<%= base_name %>/app/views/*
120
+ 2. gems/<%= base_name %>/app/views/*
121
+ 3. host-app/app/views/*
122
+
123
+ You can use the host application's layout by configuring the
124
+ <%= base_name %> slice in a before_app_loads block:
125
+
126
+ Merb::Slices.config[:<%= underscored_name %>] = { :layout => :application }
127
+
128
+ By default :<%= underscored_name %> is used. If you need to override
129
+ stylesheets or javascripts, just specify your own files in your layout
130
+ instead/in addition to the ones supplied (if any) in
131
+ host-app/public/slices/<%= base_name %>.
132
+
133
+ In any case don't edit those files directly as they may be clobbered any time
134
+ rake <%= underscored_name %>:install is run.
135
+
136
+ ------------------------------------------------------------------------------
137
+
138
+ About Slices
139
+ ============
140
+
141
+ Merb-Slices is a Merb plugin for using and creating application 'slices' which
142
+ help you modularize your application. Usually these are reuseable extractions
143
+ from your main app. In effect, a Slice is just like a regular Merb MVC
144
+ application, both in functionality as well as in structure.
145
+
146
+ When you generate a Slice stub structure, a module is setup to serve as a
147
+ namespace for your controller, models, helpers etc. This ensures maximum
148
+ encapsulation. You could say a Slice is a mixture between a Merb plugin (a
149
+ Gem) and a Merb application, reaping the benefits of both.
150
+
151
+ A host application can 'mount' a Slice inside the router, which means you have
152
+ full over control how it integrates. By default a Slice's routes are prefixed
153
+ by its name (a router :namespace), but you can easily provide your own prefix
154
+ or leave it out, mounting it at the root of your url-schema. You can even
155
+ mount a Slice multiple times and give extra parameters to customize an
156
+ instance's behaviour.
157
+
158
+ A Slice's Application controller uses controller_for_slice to setup slice
159
+ specific behaviour, which mainly affects cascaded view handling. Additionaly,
160
+ this method is available to any kind of controller, so it can be used for
161
+ Merb Mailer too for example.
162
+
163
+ There are many ways which let you customize a Slice's functionality and
164
+ appearance without ever touching the Gem-level code itself. It's not only easy
165
+ to add template/layout overrides, you can also add/modify controllers, models
166
+ and other runtime code from within the host application.
167
+
168
+ To create your own Slice run this (somewhere outside of your merb app):
169
+
170
+ $ merb-gen slice <your-lowercase-slice-name>
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec/rake/spectask'
4
+ require 'merb-core/version'
5
+ require 'merb-core/test/tasks/spectasks'
6
+ require 'merb-core/tasks/merb_rake_helper'
7
+
8
+ NAME = "<%= base_name %>"
9
+ AUTHOR = "Your Name"
10
+ EMAIL = "Your Email"
11
+ HOMEPAGE = "http://merbivore.com/"
12
+ SUMMARY = "Merb Slice that provides ..."
13
+ GEM_VERSION = "<%= Merb::VERSION %>"
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.rubyforge_project = 'merb'
17
+ s.name = NAME
18
+ s.version = GEM_VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
22
+ s.summary = SUMMARY
23
+ s.description = s.summary
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+ s.add_dependency('merb-slices', '>= <%= Merb::VERSION %>')
28
+ s.require_path = 'lib'
29
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ desc "Install <%= module_name %> as a gem"
37
+ task :install => [:package] do
38
+ sh %{#{sudo} gem install pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
39
+ end
40
+
41
+ namespace :jruby do
42
+
43
+ desc "Run :package and install the resulting .gem with jruby"
44
+ task :install => :package do
45
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
46
+ end
47
+
48
+ end
@@ -0,0 +1,15 @@
1
+ TODO:
2
+
3
+ - Fix <%= module_name %>.description and <%= module_name %>.version
4
+ - Fix LICENSE with your name
5
+ - Fix Rakefile with your name and contact info
6
+ - Add your code to lib/<%= base_name %>.rb
7
+ - Add your Merb rake tasks to lib/<%= base_name %>/merbtasks.rb
8
+
9
+ Remove anything that you don't need:
10
+
11
+ - app/controllers/main.rb <%= module_name %>::Main controller
12
+ - app/views/layout/<%= underscored_name %>.html.erb
13
+ - spec/controllers/main_spec.rb controller specs
14
+ - public/* any public files
15
+ - stubs/* any stub files
@@ -0,0 +1,5 @@
1
+ class <%= module_name %>::Application < Merb::Controller
2
+
3
+ controller_for_slice
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ class <%= module_name %>::Main < <%= module_name %>::Application
2
+
3
+ def index
4
+ render
5
+ end
6
+
7
+ end
@@ -0,0 +1,64 @@
1
+ module Merb
2
+ module <%= module_name %>
3
+ module ApplicationHelper
4
+
5
+ # @param *segments<Array[#to_s]> Path segments to append.
6
+ #
7
+ # @return <String>
8
+ # A path relative to the public directory, with added segments.
9
+ def image_path(*segments)
10
+ public_path_for(:image, *segments)
11
+ end
12
+
13
+ # @param *segments<Array[#to_s]> Path segments to append.
14
+ #
15
+ # @return <String>
16
+ # A path relative to the public directory, with added segments.
17
+ def javascript_path(*segments)
18
+ public_path_for(:javascript, *segments)
19
+ end
20
+
21
+ # @param *segments<Array[#to_s]> Path segments to append.
22
+ #
23
+ # @return <String>
24
+ # A path relative to the public directory, with added segments.
25
+ def stylesheet_path(*segments)
26
+ public_path_for(:stylesheet, *segments)
27
+ end
28
+
29
+ # Construct a path relative to the public directory
30
+ #
31
+ # @param <Symbol> The type of component.
32
+ # @param *segments<Array[#to_s]> Path segments to append.
33
+ #
34
+ # @return <String>
35
+ # A path relative to the public directory, with added segments.
36
+ def public_path_for(type, *segments)
37
+ ::<%= module_name %>.public_path_for(type, *segments)
38
+ end
39
+
40
+ # Construct an app-level path.
41
+ #
42
+ # @param <Symbol> The type of component.
43
+ # @param *segments<Array[#to_s]> Path segments to append.
44
+ #
45
+ # @return <String>
46
+ # A path within the host application, with added segments.
47
+ def app_path_for(type, *segments)
48
+ ::<%= module_name %>.app_path_for(type, *segments)
49
+ end
50
+
51
+ # Construct a slice-level path.
52
+ #
53
+ # @param <Symbol> The type of component.
54
+ # @param *segments<Array[#to_s]> Path segments to append.
55
+ #
56
+ # @return <String>
57
+ # A path within the slice source (Gem), with added segments.
58
+ def slice_path_for(type, *segments)
59
+ ::<%= module_name %>.slice_path_for(type, *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>Fresh <%= module_name %> Slice</title>
6
+ <link href="<%%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
7
+ <script src="<%%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
8
+ </head>
9
+ <!-- you can override this layout at slices/<%= base_name %>/app/views/layout/<%= underscored_name %>.html.erb -->
10
+ <body class="<%= base_name %>-slice">
11
+ <div id="container">
12
+ <h1><%= module_name %> Slice</h1>
13
+ <div id="main"><%%= catch_content :for_layout %></div>
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1 @@
1
+ <strong><%%= slice.description %></strong> (v. <%%= slice.version %>)
@@ -0,0 +1,78 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ load_dependency 'merb-slices'
6
+ Merb::Plugins.add_rakefiles "<%= base_name %>/merbtasks", "<%= base_name %>/slicetasks"
7
+
8
+ # Register the Slice for the current host application
9
+ Merb::Slices::register(__FILE__)
10
+
11
+ # Slice configuration - set this in a before_app_loads callback.
12
+ # By default a Slice uses its own layout, so you can swicht to
13
+ # the main application layout or no layout at all if needed.
14
+ #
15
+ # Configuration options:
16
+ # :layout - the layout to use; defaults to :<%= underscored_name %>
17
+ # :mirror - which path component types to use on copy operations; defaults to all
18
+ Merb::Slices::config[:<%= underscored_name %>][:layout] ||= :<%= underscored_name %>
19
+
20
+ # All Slice code is expected to be namespaced inside a module
21
+ module <%= module_name %>
22
+
23
+ # Slice metadata
24
+ self.description = "<%= module_name %> is a chunky Merb slice!"
25
+ self.version = "0.0.1"
26
+ self.author = "YOUR NAME"
27
+
28
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
29
+ # right after a slice's classes have been loaded internally.
30
+ def self.loaded
31
+ end
32
+
33
+ # Initialization hook - runs before AfterAppLoads BootLoader
34
+ def self.init
35
+ end
36
+
37
+ # Activation hook - runs after AfterAppLoads BootLoader
38
+ def self.activate
39
+ end
40
+
41
+ # Deactivation hook - triggered by Merb::Slices.deactivate(<%= module_name %>)
42
+ def self.deactivate
43
+ end
44
+
45
+ # Setup routes inside the host application
46
+ #
47
+ # @param scope<Merb::Router::Behaviour>
48
+ # Routes will be added within this scope (namespace). In fact, any
49
+ # router behaviour is a valid namespace, so you can attach
50
+ # routes at any level of your router setup.
51
+ #
52
+ # @note prefix your named routes with :<%= underscored_name %>_
53
+ # to avoid potential conflicts with global named routes.
54
+ def self.setup_router(scope)
55
+ # example of a named route
56
+ scope.match('/index.:format').to(:controller => 'main', :action => 'index').name(:<%= underscored_name %>_index)
57
+ end
58
+
59
+ end
60
+
61
+ # Setup the slice layout for <%= module_name %>
62
+ #
63
+ # Use <%= module_name %>.push_path and <%= module_name %>.push_app_path
64
+ # to set paths to <%= base_name %>-level and app-level paths. Example:
65
+ #
66
+ # <%= module_name %>.push_path(:application, <%= module_name %>.root)
67
+ # <%= module_name %>.push_app_path(:application, Merb.root / 'slices' / '<%= base_name %>')
68
+ # ...
69
+ #
70
+ # Any component path that hasn't been set will default to <%= module_name %>.root
71
+ #
72
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
73
+ <%= module_name %>.setup_default_structure!
74
+
75
+ # Add dependencies for other <%= module_name %> classes below. Example:
76
+ # dependency "<%= base_name %>/other"
77
+
78
+ end
@@ -0,0 +1,166 @@
1
+ namespace :slices do
2
+ namespace :<%= underscored_name %> do
3
+
4
+ desc "Install <%= module_name %>"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ <%= module_name %>.mirrored_components.each do |type|
15
+ if File.directory?(<%= module_name %>.dir_for(type))
16
+ if !File.directory?(dst_path = <%= module_name %>.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for <%= module_name %> - resolves any collisions"
28
+ copied, preserved = <%= module_name %>.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for <%= module_name %> - resolves any collisions"
40
+ copied, preserved = <%= module_name %>.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze <%= module_name %> into your app (only <%= base_name %>/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ desc "Freezes <%= module_name %> by installing the gem into application/gems using merb-freezer"
56
+ task :gem do
57
+ begin
58
+ Object.const_get(:Freezer).freeze(ENV["GEM"] || "<%= base_name %>", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
59
+ rescue NameError
60
+ puts "! dependency 'merb-freezer' missing"
61
+ end
62
+ end
63
+
64
+ desc "Freezes <%= module_name %> by copying all files from <%= base_name %>/app to your application"
65
+ task :app do
66
+ puts "Copying all <%= base_name %>/app files to your application - resolves any collisions"
67
+ copied, preserved = <%= module_name %>.mirror_app!
68
+ puts "- no files to copy" if copied.empty? && preserved.empty?
69
+ copied.each { |f| puts "- copied #{f}" }
70
+ preserved.each { |f| puts "! preserved override as #{f}" }
71
+ end
72
+
73
+ desc "Freeze all views into your application for easy modification"
74
+ task :views do
75
+ puts "Copying all view templates to your application - resolves any collisions"
76
+ copied, preserved = <%= module_name %>.mirror_files_for :view
77
+ puts "- no files to copy" if copied.empty? && preserved.empty?
78
+ copied.each { |f| puts "- copied #{f}" }
79
+ preserved.each { |f| puts "! preserved override as #{f}" }
80
+ end
81
+
82
+ desc "Freeze all models into your application for easy modification"
83
+ task :models do
84
+ puts "Copying all models to your application - resolves any collisions"
85
+ copied, preserved = <%= module_name %>.mirror_files_for :model
86
+ puts "- no files to copy" if copied.empty? && preserved.empty?
87
+ copied.each { |f| puts "- copied #{f}" }
88
+ preserved.each { |f| puts "! preserved override as #{f}" }
89
+ end
90
+
91
+ desc "Freezes <%= module_name %> as a gem and copies over <%= base_name %>/app"
92
+ task :app_with_gem => [:gem, :app]
93
+
94
+ desc "Freezes <%= module_name %> by unpacking all files into your application"
95
+ task :unpack do
96
+ puts "Unpacking <%= module_name %> files to your application - resolves any collisions"
97
+ copied, preserved = <%= module_name %>.unpack_slice!
98
+ puts "- no files to copy" if copied.empty? && preserved.empty?
99
+ copied.each { |f| puts "- copied #{f}" }
100
+ preserved.each { |f| puts "! preserved override as #{f}" }
101
+ end
102
+
103
+ end
104
+
105
+ desc "Run slice specs within the host application context"
106
+ task :spec => [ "spec:explain", "spec:default" ]
107
+
108
+ namespace :spec do
109
+
110
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
111
+
112
+ task :explain do
113
+ puts "\nNote: By running <%= module_name %> specs inside the application context any\n" +
114
+ "overrides could break existing specs. This isn't always a problem,\n" +
115
+ "especially in the case of views. Use these spec tasks to check how\n" +
116
+ "well your application conforms to the original slice implementation."
117
+ end
118
+
119
+ Spec::Rake::SpecTask.new('default') do |t|
120
+ t.spec_opts = ["--format", "specdoc", "--colour"]
121
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
122
+ end
123
+
124
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
125
+ Spec::Rake::SpecTask.new('model') do |t|
126
+ t.spec_opts = ["--format", "specdoc", "--colour"]
127
+ if(ENV['MODEL'])
128
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
129
+ else
130
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
131
+ end
132
+ end
133
+
134
+ desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
135
+ Spec::Rake::SpecTask.new('controller') do |t|
136
+ t.spec_opts = ["--format", "specdoc", "--colour"]
137
+ if(ENV['CONTROLLER'])
138
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
139
+ else
140
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
141
+ end
142
+ end
143
+
144
+ desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
145
+ Spec::Rake::SpecTask.new('view') do |t|
146
+ t.spec_opts = ["--format", "specdoc", "--colour"]
147
+ if(ENV['CONTROLLER'] and ENV['VIEW'])
148
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
149
+ elsif(ENV['CONTROLLER'])
150
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
151
+ else
152
+ t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
153
+ end
154
+ end
155
+
156
+ desc "Run all specs and output the result in html"
157
+ Spec::Rake::SpecTask.new('html') do |t|
158
+ t.spec_opts = ["--format", "html"]
159
+ t.libs = ['lib', 'server/lib' ]
160
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
161
+ end
162
+
163
+ end
164
+
165
+ end
166
+ end