merb-slices 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.
- data/Generators +4 -0
- data/LICENSE +20 -0
- data/README +102 -0
- data/Rakefile +65 -0
- data/TODO +0 -0
- data/lib/generators/base.rb +21 -0
- data/lib/generators/full.rb +21 -0
- data/lib/generators/templates/full/LICENSE +20 -0
- data/lib/generators/templates/full/README +170 -0
- data/lib/generators/templates/full/Rakefile +48 -0
- data/lib/generators/templates/full/TODO +15 -0
- data/lib/generators/templates/full/app/controllers/application.rb +5 -0
- data/lib/generators/templates/full/app/controllers/main.rb +7 -0
- data/lib/generators/templates/full/app/helpers/application_helper.rb +64 -0
- data/lib/generators/templates/full/app/views/layout/%symbol_name%.html.erb +16 -0
- data/lib/generators/templates/full/app/views/main/index.html.erb +1 -0
- data/lib/generators/templates/full/lib/%base_name%.rb +78 -0
- data/lib/generators/templates/full/lib/%base_name%/merbtasks.rb +166 -0
- data/lib/generators/templates/full/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/templates/full/public/javascripts/master.js +0 -0
- data/lib/generators/templates/full/public/stylesheets/master.css +2 -0
- data/lib/generators/templates/full/spec/%base_name%_spec.rb +130 -0
- data/lib/generators/templates/full/spec/controllers/main_spec.rb +61 -0
- data/lib/generators/templates/full/spec/spec_helper.rb +44 -0
- data/lib/generators/templates/full/stubs/app/controllers/application.rb +2 -0
- data/lib/generators/templates/full/stubs/app/controllers/main.rb +2 -0
- data/lib/generators/templates/thin/LICENSE +20 -0
- data/lib/generators/templates/thin/README +130 -0
- data/lib/generators/templates/thin/Rakefile +46 -0
- data/lib/generators/templates/thin/TODO +7 -0
- data/lib/generators/templates/thin/application.rb +36 -0
- data/lib/generators/templates/thin/lib/%base_name%.rb +93 -0
- data/lib/generators/templates/thin/lib/%base_name%/merbtasks.rb +106 -0
- data/lib/generators/templates/thin/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/templates/thin/public/javascripts/master.js +0 -0
- data/lib/generators/templates/thin/public/stylesheets/master.css +2 -0
- data/lib/generators/templates/thin/stubs/application.rb +9 -0
- data/lib/generators/templates/thin/views/layout/%symbol_name%.html.erb +16 -0
- data/lib/generators/templates/thin/views/main/index.html.erb +1 -0
- data/lib/generators/templates/very_thin/LICENSE +20 -0
- data/lib/generators/templates/very_thin/README +110 -0
- data/lib/generators/templates/very_thin/Rakefile +46 -0
- data/lib/generators/templates/very_thin/TODO +7 -0
- data/lib/generators/templates/very_thin/application.rb +36 -0
- data/lib/generators/templates/very_thin/lib/%base_name%.rb +89 -0
- data/lib/generators/templates/very_thin/lib/%base_name%/merbtasks.rb +106 -0
- data/lib/generators/templates/very_thin/lib/%base_name%/slicetasks.rb +18 -0
- data/lib/generators/thin.rb +21 -0
- data/lib/generators/very_thin.rb +21 -0
- data/lib/merb-slices.rb +126 -0
- data/lib/merb-slices/controller_mixin.rb +129 -0
- data/lib/merb-slices/merbtasks.rb +19 -0
- data/lib/merb-slices/module.rb +338 -0
- data/lib/merb-slices/module_mixin.rb +535 -0
- data/lib/merb-slices/router_ext.rb +75 -0
- data/spec/full_slice_generator_spec.rb +21 -0
- data/spec/merb-slice_spec.rb +7 -0
- data/spec/slice_generator_spec.rb +22 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/thin_slice_generator_spec.rb +21 -0
- data/spec/very_thin_slice_generator_spec.rb +21 -0
- metadata +157 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
module Merb
|
2
|
+
class Router
|
3
|
+
|
4
|
+
class Behavior
|
5
|
+
|
6
|
+
# Add all known slices to the router
|
7
|
+
#
|
8
|
+
# By combining this with Merb::Slices.activate_by_file and Merb::Slices.deactivate
|
9
|
+
# one can enable/disable slices at runtime, without restarting your app.
|
10
|
+
#
|
11
|
+
# @param config<Hash>
|
12
|
+
# Optional hash, mapping slice module names to their settings;
|
13
|
+
# set :path (or use a string) if you want to override what appears on the url.
|
14
|
+
#
|
15
|
+
# @yield A new Behavior instance is yielded in the block for nested routes.
|
16
|
+
# @yieldparam ns<Behavior> The namespace behavior object.
|
17
|
+
#
|
18
|
+
# @example r.all_slices('BlogSlice' => 'blog', 'ForumSlice' => { :path => 'forum' })
|
19
|
+
#
|
20
|
+
# @note The block is yielded for each slice individually.
|
21
|
+
def all_slices(config = {}, &block)
|
22
|
+
Merb::Slices.slice_names.each { |module_name| add_slice(module_name, config[module_name] || {}, &block) }
|
23
|
+
end
|
24
|
+
alias :add_slices :all_slices
|
25
|
+
|
26
|
+
# Add a Slice in a router namespace
|
27
|
+
#
|
28
|
+
# @param slice_module<String, Symbol, Module> A Slice module to mount.
|
29
|
+
# @param options<Hash, String> Optional hash, set :path if you want to override what appears on the url.
|
30
|
+
#
|
31
|
+
# @yield A new Behavior instance is yielded in the block for nested routes - runs before the slice routes are setup.
|
32
|
+
# @yieldparam ns<Behavior> The namespace behavior object.
|
33
|
+
#
|
34
|
+
# @return <Behaviour> The current router context.
|
35
|
+
#
|
36
|
+
# @note If a slice has no routes at all, the activate hook won't be executed.
|
37
|
+
#
|
38
|
+
# @note Normally you should specify the slice_module using a String or Symbol
|
39
|
+
# this ensures that your module can be removed from the router at runtime.
|
40
|
+
def add_slice(slice_module, options = {}, &block)
|
41
|
+
if Merb::Slices.exists?(slice_module)
|
42
|
+
options = { :path => options } if options.is_a?(String)
|
43
|
+
slice_module = Object.full_const_get(slice_module.to_s) if slice_module.class.in?(String, Symbol)
|
44
|
+
namespace = options[:namespace] || slice_module.to_s.snake_case
|
45
|
+
options[:path] ||= slice_module[:path_prefix] || options[:namespace] || slice_module.identifier
|
46
|
+
options[:default_routes] = true unless options.key?(:default_routes)
|
47
|
+
options[:prepend_routes] = block if block_given?
|
48
|
+
slice_module[:path_prefix] = options[:path]
|
49
|
+
Merb.logger.info!("Mounting slice #{slice_module} at /#{options[:path]}")
|
50
|
+
|
51
|
+
# setup routes - capture the slice's routes for easy reference
|
52
|
+
slice_module.routes, slice_module.named_routes = Merb::Router.capture do
|
53
|
+
self.namespace(namespace.to_sym, options.except(:default_routes, :prepend_routes, :append_routes)) do |ns|
|
54
|
+
options[:prepend_routes].call(ns) if options[:prepend_routes].respond_to?(:call)
|
55
|
+
slice_module.setup_router(ns) # setup the routes from the slice itself
|
56
|
+
options[:append_routes].call(ns) if options[:append_routes].respond_to?(:call)
|
57
|
+
ns.default_routes(options[:params] || {}) if options[:default_routes]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
else
|
61
|
+
Merb.logger.info!("Skipped adding slice #{slice_module} to router...")
|
62
|
+
end
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
# Insert a slice directly into the current router context.
|
67
|
+
#
|
68
|
+
# This will still setup a namespace, but doesn't set a path prefix.
|
69
|
+
def slice(slice_module, options = {}, &block)
|
70
|
+
add_slice(slice_module, options.merge(:path => ''), &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Generators::FullSliceGenerator do
|
4
|
+
|
5
|
+
include Merb::Test::GeneratorHelper
|
6
|
+
|
7
|
+
describe "templates" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@generator = Merb::Generators::FullSliceGenerator.new('/tmp', {}, 'testing')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create a number of templates"
|
14
|
+
|
15
|
+
it "should render templates successfully" do
|
16
|
+
lambda { @generator.render! }.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Generators::SliceGenerator do
|
4
|
+
|
5
|
+
include Merb::Test::GeneratorHelper
|
6
|
+
|
7
|
+
it "should invoke the full generator by default" do
|
8
|
+
@generator = Merb::Generators::SliceGenerator.new('/tmp', {}, 'testing')
|
9
|
+
@generator.should invoke(Merb::Generators::FullSliceGenerator).with('testing')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should invoke the flat generator if flat is true" do
|
13
|
+
@generator = Merb::Generators::SliceGenerator.new('/tmp', { :thin => true }, 'testing')
|
14
|
+
@generator.should invoke(Merb::Generators::ThinSliceGenerator).with('testing')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should invoke the very flat generator if very flat is true" do
|
18
|
+
@generator = Merb::Generators::SliceGenerator.new('/tmp', { :very_thin => true }, 'testing')
|
19
|
+
@generator.should invoke(Merb::Generators::VeryThinSliceGenerator).with('testing')
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Generators::ThinSliceGenerator do
|
4
|
+
|
5
|
+
include Merb::Test::GeneratorHelper
|
6
|
+
|
7
|
+
describe "templates" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@generator = Merb::Generators::ThinSliceGenerator.new('/tmp', {}, 'testing')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create a number of templates"
|
14
|
+
|
15
|
+
it "should render templates successfully" do
|
16
|
+
lambda { @generator.render! }.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Merb::Generators::VeryThinSliceGenerator do
|
4
|
+
|
5
|
+
include Merb::Test::GeneratorHelper
|
6
|
+
|
7
|
+
describe "templates" do
|
8
|
+
|
9
|
+
before do
|
10
|
+
@generator = Merb::Generators::VeryThinSliceGenerator.new('/tmp', {}, 'testing')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create a number of templates"
|
14
|
+
|
15
|
+
it "should render templates successfully" do
|
16
|
+
lambda { @generator.render! }.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: merb-slices
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabien Franzen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-13 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.4
|
24
|
+
version:
|
25
|
+
description: Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application.
|
26
|
+
email: info@fabien.be
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- LICENSE
|
34
|
+
- TODO
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- Generators
|
40
|
+
- TODO
|
41
|
+
- lib/generators
|
42
|
+
- lib/generators/base.rb
|
43
|
+
- lib/generators/full.rb
|
44
|
+
- lib/generators/templates
|
45
|
+
- lib/generators/templates/full
|
46
|
+
- lib/generators/templates/full/app
|
47
|
+
- lib/generators/templates/full/app/controllers
|
48
|
+
- lib/generators/templates/full/app/controllers/application.rb
|
49
|
+
- lib/generators/templates/full/app/controllers/main.rb
|
50
|
+
- lib/generators/templates/full/app/helpers
|
51
|
+
- lib/generators/templates/full/app/helpers/application_helper.rb
|
52
|
+
- lib/generators/templates/full/app/views
|
53
|
+
- lib/generators/templates/full/app/views/layout
|
54
|
+
- lib/generators/templates/full/app/views/layout/%symbol_name%.html.erb
|
55
|
+
- lib/generators/templates/full/app/views/main
|
56
|
+
- lib/generators/templates/full/app/views/main/index.html.erb
|
57
|
+
- lib/generators/templates/full/lib
|
58
|
+
- lib/generators/templates/full/lib/%base_name%
|
59
|
+
- lib/generators/templates/full/lib/%base_name%/merbtasks.rb
|
60
|
+
- lib/generators/templates/full/lib/%base_name%/slicetasks.rb
|
61
|
+
- lib/generators/templates/full/lib/%base_name%.rb
|
62
|
+
- lib/generators/templates/full/LICENSE
|
63
|
+
- lib/generators/templates/full/public
|
64
|
+
- lib/generators/templates/full/public/javascripts
|
65
|
+
- lib/generators/templates/full/public/javascripts/master.js
|
66
|
+
- lib/generators/templates/full/public/stylesheets
|
67
|
+
- lib/generators/templates/full/public/stylesheets/master.css
|
68
|
+
- lib/generators/templates/full/Rakefile
|
69
|
+
- lib/generators/templates/full/README
|
70
|
+
- lib/generators/templates/full/spec
|
71
|
+
- lib/generators/templates/full/spec/%base_name%_spec.rb
|
72
|
+
- lib/generators/templates/full/spec/controllers
|
73
|
+
- lib/generators/templates/full/spec/controllers/main_spec.rb
|
74
|
+
- lib/generators/templates/full/spec/spec_helper.rb
|
75
|
+
- lib/generators/templates/full/stubs
|
76
|
+
- lib/generators/templates/full/stubs/app
|
77
|
+
- lib/generators/templates/full/stubs/app/controllers
|
78
|
+
- lib/generators/templates/full/stubs/app/controllers/application.rb
|
79
|
+
- lib/generators/templates/full/stubs/app/controllers/main.rb
|
80
|
+
- lib/generators/templates/full/TODO
|
81
|
+
- lib/generators/templates/thin
|
82
|
+
- lib/generators/templates/thin/application.rb
|
83
|
+
- lib/generators/templates/thin/lib
|
84
|
+
- lib/generators/templates/thin/lib/%base_name%
|
85
|
+
- lib/generators/templates/thin/lib/%base_name%/merbtasks.rb
|
86
|
+
- lib/generators/templates/thin/lib/%base_name%/slicetasks.rb
|
87
|
+
- lib/generators/templates/thin/lib/%base_name%.rb
|
88
|
+
- lib/generators/templates/thin/LICENSE
|
89
|
+
- lib/generators/templates/thin/public
|
90
|
+
- lib/generators/templates/thin/public/javascripts
|
91
|
+
- lib/generators/templates/thin/public/javascripts/master.js
|
92
|
+
- lib/generators/templates/thin/public/stylesheets
|
93
|
+
- lib/generators/templates/thin/public/stylesheets/master.css
|
94
|
+
- lib/generators/templates/thin/Rakefile
|
95
|
+
- lib/generators/templates/thin/README
|
96
|
+
- lib/generators/templates/thin/stubs
|
97
|
+
- lib/generators/templates/thin/stubs/application.rb
|
98
|
+
- lib/generators/templates/thin/TODO
|
99
|
+
- lib/generators/templates/thin/views
|
100
|
+
- lib/generators/templates/thin/views/layout
|
101
|
+
- lib/generators/templates/thin/views/layout/%symbol_name%.html.erb
|
102
|
+
- lib/generators/templates/thin/views/main
|
103
|
+
- lib/generators/templates/thin/views/main/index.html.erb
|
104
|
+
- lib/generators/templates/very_thin
|
105
|
+
- lib/generators/templates/very_thin/application.rb
|
106
|
+
- lib/generators/templates/very_thin/lib
|
107
|
+
- lib/generators/templates/very_thin/lib/%base_name%
|
108
|
+
- lib/generators/templates/very_thin/lib/%base_name%/merbtasks.rb
|
109
|
+
- lib/generators/templates/very_thin/lib/%base_name%/slicetasks.rb
|
110
|
+
- lib/generators/templates/very_thin/lib/%base_name%.rb
|
111
|
+
- lib/generators/templates/very_thin/LICENSE
|
112
|
+
- lib/generators/templates/very_thin/Rakefile
|
113
|
+
- lib/generators/templates/very_thin/README
|
114
|
+
- lib/generators/templates/very_thin/TODO
|
115
|
+
- lib/generators/thin.rb
|
116
|
+
- lib/generators/very_thin.rb
|
117
|
+
- lib/merb-slices
|
118
|
+
- lib/merb-slices/controller_mixin.rb
|
119
|
+
- lib/merb-slices/merbtasks.rb
|
120
|
+
- lib/merb-slices/module.rb
|
121
|
+
- lib/merb-slices/module_mixin.rb
|
122
|
+
- lib/merb-slices/router_ext.rb
|
123
|
+
- lib/merb-slices.rb
|
124
|
+
- spec/full_slice_generator_spec.rb
|
125
|
+
- spec/merb-slice_spec.rb
|
126
|
+
- spec/slice_generator_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/thin_slice_generator_spec.rb
|
129
|
+
- spec/very_thin_slice_generator_spec.rb
|
130
|
+
has_rdoc: true
|
131
|
+
homepage: http://merbivore.com
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: "0"
|
142
|
+
version:
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: "0"
|
148
|
+
version:
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project: merb
|
152
|
+
rubygems_version: 1.2.0
|
153
|
+
signing_key:
|
154
|
+
specification_version: 2
|
155
|
+
summary: Merb-Slices is a Merb plugin for using and creating application 'slices' which help you modularize your application.
|
156
|
+
test_files: []
|
157
|
+
|