merb-slices 0.9.7 → 0.9.8
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/README +4 -4
- data/Rakefile +27 -13
- data/TODO +1 -2
- data/bin/slice +77 -0
- data/lib/generators/templates/common/Rakefile +16 -12
- data/lib/generators/templates/full/README +4 -4
- data/lib/generators/templates/full/Rakefile +32 -13
- data/lib/generators/templates/full/config/init.rb +43 -0
- data/lib/generators/templates/full/lib/%base_name%.rb +3 -1
- data/lib/generators/templates/full/spec/%base_name%_spec.rb +10 -121
- data/lib/generators/templates/full/spec/controllers/main_spec.rb +18 -8
- data/lib/generators/templates/thin/README +4 -4
- data/lib/generators/templates/very_thin/README +4 -4
- data/lib/merb-slices.rb +3 -3
- data/lib/merb-slices/controller_mixin.rb +34 -7
- data/lib/merb-slices/merbtasks.rb +5 -34
- data/lib/merb-slices/module.rb +9 -3
- data/lib/merb-slices/module_mixin.rb +19 -31
- data/lib/merb-slices/router_ext.rb +10 -7
- data/spec/full_slice_generator_spec.rb +31 -2
- data/spec/full_slice_spec.rb +162 -0
- data/spec/merb-slice_spec.rb +97 -3
- data/spec/slice_generator_spec.rb +15 -3
- data/spec/slices/full-test-slice/LICENSE +20 -0
- data/spec/slices/full-test-slice/README +170 -0
- data/spec/slices/full-test-slice/Rakefile +67 -0
- data/spec/slices/full-test-slice/TODO +15 -0
- data/spec/slices/full-test-slice/app/controllers/application.rb +5 -0
- data/spec/slices/full-test-slice/app/controllers/main.rb +7 -0
- data/spec/slices/full-test-slice/app/helpers/application_helper.rb +64 -0
- data/spec/slices/full-test-slice/app/views/layout/full_test_slice.html.erb +16 -0
- data/spec/slices/full-test-slice/app/views/main/index.html.erb +1 -0
- data/spec/slices/full-test-slice/config/init.rb +43 -0
- data/spec/slices/full-test-slice/lib/full-test-slice.rb +80 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/merbtasks.rb +103 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/slicetasks.rb +18 -0
- data/spec/slices/full-test-slice/lib/full-test-slice/spectasks.rb +65 -0
- data/spec/slices/full-test-slice/public/javascripts/master.js +0 -0
- data/spec/slices/full-test-slice/public/stylesheets/master.css +2 -0
- data/spec/slices/full-test-slice/stubs/app/controllers/application.rb +2 -0
- data/spec/slices/full-test-slice/stubs/app/controllers/main.rb +2 -0
- data/spec/slices/thin-test-slice/LICENSE +20 -0
- data/spec/slices/thin-test-slice/README +130 -0
- data/spec/slices/thin-test-slice/Rakefile +43 -0
- data/spec/slices/thin-test-slice/TODO +7 -0
- data/spec/slices/thin-test-slice/application.rb +36 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice.rb +93 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice/merbtasks.rb +103 -0
- data/spec/slices/thin-test-slice/lib/thin-test-slice/slicetasks.rb +18 -0
- data/spec/slices/thin-test-slice/public/javascripts/master.js +0 -0
- data/spec/slices/thin-test-slice/public/stylesheets/master.css +2 -0
- data/spec/slices/thin-test-slice/stubs/application.rb +9 -0
- data/spec/slices/thin-test-slice/views/layout/thin_test_slice.html.erb +16 -0
- data/spec/slices/thin-test-slice/views/main/index.html.erb +1 -0
- data/spec/slices/very-thin-test-slice/LICENSE +20 -0
- data/spec/slices/very-thin-test-slice/README +110 -0
- data/spec/slices/very-thin-test-slice/Rakefile +43 -0
- data/spec/slices/very-thin-test-slice/TODO +7 -0
- data/spec/slices/very-thin-test-slice/application.rb +36 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice.rb +89 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice/merbtasks.rb +103 -0
- data/spec/slices/very-thin-test-slice/lib/very-thin-test-slice/slicetasks.rb +18 -0
- data/spec/spec_helper.rb +27 -2
- data/spec/thin_slice_generator_spec.rb +24 -2
- data/spec/thin_slice_spec.rb +139 -0
- data/spec/very_thin_slice_generator_spec.rb +22 -2
- data/spec/very_thin_slice_spec.rb +119 -0
- metadata +79 -5
@@ -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 FullTestSlice 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/full-test-slice/app/views/layout/full-test-slice.html.erb -->
|
10
|
+
<body class="full-test-slice-slice">
|
11
|
+
<div id="container">
|
12
|
+
<h1>FullTestSlice 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,43 @@
|
|
1
|
+
#
|
2
|
+
# ==== Standalone FullTestSlice configuration
|
3
|
+
#
|
4
|
+
# This configuration/environment file is only loaded by bin/slice, which can be
|
5
|
+
# used during development of the slice. It has no effect on this slice being
|
6
|
+
# loaded in a host application. To run your slice in standalone mode, just
|
7
|
+
# run 'slice' from its directory. The 'slice' command is very similar to
|
8
|
+
# the 'merb' command, and takes all the same options, including -i to drop
|
9
|
+
# into an irb session for example.
|
10
|
+
#
|
11
|
+
# The usual Merb configuration directives and init.rb setup methods apply,
|
12
|
+
# including use_orm and before_app_loads/after_app_loads.
|
13
|
+
#
|
14
|
+
# If you need need different configurations for different environments you can
|
15
|
+
# even create the specific environment file in config/environments/ just like
|
16
|
+
# in a regular Merb application.
|
17
|
+
#
|
18
|
+
# In fact, a slice is no different from a normal # Merb application - it only
|
19
|
+
# differs by the fact that seamlessly integrates into a so called 'host'
|
20
|
+
# application, which in turn can override or finetune the slice implementation
|
21
|
+
# code and views.
|
22
|
+
#
|
23
|
+
|
24
|
+
Merb::Config.use do |c|
|
25
|
+
|
26
|
+
# Sets up a custom session id key which is used for the session persistence
|
27
|
+
# cookie name. If not specified, defaults to '_session_id'.
|
28
|
+
# c[:session_id_key] = '_session_id'
|
29
|
+
|
30
|
+
# The session_secret_key is only required for the cookie session store.
|
31
|
+
c[:session_secret_key] = '780af855b5f47a1033726be3fabad8113a3d34a4'
|
32
|
+
|
33
|
+
# There are various options here, by default Merb comes with 'cookie',
|
34
|
+
# 'memory', 'memcache' or 'container'.
|
35
|
+
# You can of course use your favorite ORM instead:
|
36
|
+
# 'datamapper', 'sequel' or 'activerecord'.
|
37
|
+
c[:session_store] = 'cookie'
|
38
|
+
|
39
|
+
# When running a slice standalone, you're usually developing it,
|
40
|
+
# so enable template reloading by default.
|
41
|
+
c[:reload_templates] = true
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
load_dependency 'merb-slices'
|
6
|
+
Merb::Plugins.add_rakefiles "full-test-slice/merbtasks", "full-test-slice/slicetasks", "full-test-slice/spectasks"
|
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 :full-test-slice
|
17
|
+
# :mirror - which path component types to use on copy operations; defaults to all
|
18
|
+
Merb::Slices::config[:full_test_slice][:layout] ||= :full_test_slice
|
19
|
+
|
20
|
+
# All Slice code is expected to be namespaced inside a module
|
21
|
+
module FullTestSlice
|
22
|
+
|
23
|
+
# Slice metadata
|
24
|
+
self.description = "FullTestSlice 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(FullTestSlice)
|
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 :full_test_slice_
|
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(:index)
|
57
|
+
# the slice is mounted at /full-test-slice - note that it comes before default_routes
|
58
|
+
scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
# Setup the slice layout for FullTestSlice
|
64
|
+
#
|
65
|
+
# Use FullTestSlice.push_path and FullTestSlice.push_app_path
|
66
|
+
# to set paths to full-test-slice-level and app-level paths. Example:
|
67
|
+
#
|
68
|
+
# FullTestSlice.push_path(:application, FullTestSlice.root)
|
69
|
+
# FullTestSlice.push_app_path(:application, Merb.root / 'slices' / 'full-test-slice')
|
70
|
+
# ...
|
71
|
+
#
|
72
|
+
# Any component path that hasn't been set will default to FullTestSlice.root
|
73
|
+
#
|
74
|
+
# Or just call setup_default_structure! to setup a basic Merb MVC structure.
|
75
|
+
FullTestSlice.setup_default_structure!
|
76
|
+
|
77
|
+
# Add dependencies for other FullTestSlice classes below. Example:
|
78
|
+
# dependency "full-test-slice/other"
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :full_test_slice do
|
3
|
+
|
4
|
+
desc "Install FullTestSlice"
|
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
|
+
FullTestSlice.mirrored_components.each do |type|
|
15
|
+
if File.directory?(FullTestSlice.dir_for(type))
|
16
|
+
if !File.directory?(dst_path = FullTestSlice.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 FullTestSlice - resolves any collisions"
|
28
|
+
copied, preserved = FullTestSlice.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 FullTestSlice - resolves any collisions"
|
40
|
+
copied, preserved = FullTestSlice.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 FullTestSlice into your app (only full-test-slice/app)"
|
51
|
+
task :freeze => [ "freeze:app" ]
|
52
|
+
|
53
|
+
namespace :freeze do
|
54
|
+
|
55
|
+
desc "Freezes FullTestSlice by installing the gem into application/gems"
|
56
|
+
task :gem do
|
57
|
+
ENV["GEM"] ||= "full-test-slice"
|
58
|
+
Rake::Task['slices:install_as_gem'].invoke
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Freezes FullTestSlice by copying all files from full-test-slice/app to your application"
|
62
|
+
task :app do
|
63
|
+
puts "Copying all full-test-slice/app files to your application - resolves any collisions"
|
64
|
+
copied, preserved = FullTestSlice.mirror_app!
|
65
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
66
|
+
copied.each { |f| puts "- copied #{f}" }
|
67
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Freeze all views into your application for easy modification"
|
71
|
+
task :views do
|
72
|
+
puts "Copying all view templates to your application - resolves any collisions"
|
73
|
+
copied, preserved = FullTestSlice.mirror_files_for :view
|
74
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
75
|
+
copied.each { |f| puts "- copied #{f}" }
|
76
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "Freeze all models into your application for easy modification"
|
80
|
+
task :models do
|
81
|
+
puts "Copying all models to your application - resolves any collisions"
|
82
|
+
copied, preserved = FullTestSlice.mirror_files_for :model
|
83
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
84
|
+
copied.each { |f| puts "- copied #{f}" }
|
85
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Freezes FullTestSlice as a gem and copies over full-test-slice/app"
|
89
|
+
task :app_with_gem => [:gem, :app]
|
90
|
+
|
91
|
+
desc "Freezes FullTestSlice by unpacking all files into your application"
|
92
|
+
task :unpack do
|
93
|
+
puts "Unpacking FullTestSlice files to your application - resolves any collisions"
|
94
|
+
copied, preserved = FullTestSlice.unpack_slice!
|
95
|
+
puts "- no files to copy" if copied.empty? && preserved.empty?
|
96
|
+
copied.each { |f| puts "- copied #{f}" }
|
97
|
+
preserved.each { |f| puts "! preserved override as #{f}" }
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :full_test_slice do
|
3
|
+
|
4
|
+
# add your own full-test-slice tasks here
|
5
|
+
|
6
|
+
# implement this to test for structural/code dependencies
|
7
|
+
# like certain directories or availability of other files
|
8
|
+
desc "Test for any dependencies"
|
9
|
+
task :preflight do
|
10
|
+
end
|
11
|
+
|
12
|
+
# implement this to perform any database related setup steps
|
13
|
+
desc "Migrate the database"
|
14
|
+
task :migrate do
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
namespace :slices do
|
2
|
+
namespace :full_test_slice do
|
3
|
+
|
4
|
+
desc "Run slice specs within the host application context"
|
5
|
+
task :spec => [ "spec:explain", "spec:default" ]
|
6
|
+
|
7
|
+
namespace :spec do
|
8
|
+
|
9
|
+
slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
10
|
+
|
11
|
+
task :explain do
|
12
|
+
puts "\nNote: By running FullTestSlice specs inside the application context any\n" +
|
13
|
+
"overrides could break existing specs. This isn't always a problem,\n" +
|
14
|
+
"especially in the case of views. Use these spec tasks to check how\n" +
|
15
|
+
"well your application conforms to the original slice implementation."
|
16
|
+
end
|
17
|
+
|
18
|
+
Spec::Rake::SpecTask.new('default') do |t|
|
19
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
20
|
+
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
|
24
|
+
Spec::Rake::SpecTask.new('model') do |t|
|
25
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
26
|
+
if(ENV['MODEL'])
|
27
|
+
t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
|
28
|
+
else
|
29
|
+
t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
|
34
|
+
Spec::Rake::SpecTask.new('controller') do |t|
|
35
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
36
|
+
if(ENV['CONTROLLER'])
|
37
|
+
t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
|
38
|
+
else
|
39
|
+
t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
|
44
|
+
Spec::Rake::SpecTask.new('view') do |t|
|
45
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
46
|
+
if(ENV['CONTROLLER'] and ENV['VIEW'])
|
47
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
|
48
|
+
elsif(ENV['CONTROLLER'])
|
49
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
|
50
|
+
else
|
51
|
+
t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Run all specs and output the result in html"
|
56
|
+
Spec::Rake::SpecTask.new('html') do |t|
|
57
|
+
t.spec_opts = ["--format", "html"]
|
58
|
+
t.libs = ['lib', 'server/lib' ]
|
59
|
+
t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 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,130 @@
|
|
1
|
+
ThinTestSlice
|
2
|
+
=============
|
3
|
+
|
4
|
+
A thin slice for the Merb framework.
|
5
|
+
|
6
|
+
------------------------------------------------------------------------------
|
7
|
+
|
8
|
+
thin-test-slice
|
9
|
+
|-- LICENSE
|
10
|
+
|-- README
|
11
|
+
|-- Rakefile [1]
|
12
|
+
|-- TODO
|
13
|
+
|-- application.rb [2]
|
14
|
+
|-- lib
|
15
|
+
| |-- thin-test-slice
|
16
|
+
| | |-- merbtasks.rb [3]
|
17
|
+
| | `-- slicetasks.rb [4]
|
18
|
+
| `-- thin-test-slice.rb [5]
|
19
|
+
|-- public [6]
|
20
|
+
| |-- javascripts
|
21
|
+
| | `-- master.js
|
22
|
+
| `-- stylesheets
|
23
|
+
| `-- master.css
|
24
|
+
|-- stubs [7]
|
25
|
+
| `-- application.rb
|
26
|
+
`-- views [8]
|
27
|
+
|-- layout
|
28
|
+
| `-- thin-test-slice.html.erb [9]
|
29
|
+
`-- main
|
30
|
+
`-- index.html.erb
|
31
|
+
|
32
|
+
|
33
|
+
1. Rake tasks to package/install the gem - edit this to modify the manifest.
|
34
|
+
2. The slice application in a single file: controllers, models, helper methods.
|
35
|
+
3. Standard rake tasks available to your application.
|
36
|
+
4. Your custom application rake tasks.
|
37
|
+
5. The main slice file - contains all slice setup logic/config.
|
38
|
+
6. Public assets you (optionally) install using rake slices:my_slice:install
|
39
|
+
7. Stubs of classes/views/files for the end-user to override - usually these
|
40
|
+
mimic the files in app/ and/or public/; use rake slices:thin-test-slice:stubs to
|
41
|
+
get started with the override stubs. Also, slices:thin-test-slice:patch will
|
42
|
+
copy over views to override in addition to the files found in /stubs.
|
43
|
+
8. A thin slice stores its views seperately.
|
44
|
+
9. The default layout, as specified in Merb::Slices::config[:my_slice][:layout]
|
45
|
+
change this to :application to use the app's layout.
|
46
|
+
|
47
|
+
|
48
|
+
To see all available tasks for ThinTestSlice run:
|
49
|
+
|
50
|
+
rake -T slices:thin-test-slice
|
51
|
+
|
52
|
+
------------------------------------------------------------------------------
|
53
|
+
|
54
|
+
Instructions for installation:
|
55
|
+
|
56
|
+
file: config/init.rb
|
57
|
+
|
58
|
+
# add the slice as a regular dependency
|
59
|
+
|
60
|
+
dependency 'thin-test-slice'
|
61
|
+
|
62
|
+
# if needed, configure which slices to load and in which order
|
63
|
+
|
64
|
+
Merb::Plugins.config[:merb_slices] = { :queue => ["ThinTestSlice", ...] }
|
65
|
+
|
66
|
+
# optionally configure the plugins in a before_app_loads callback
|
67
|
+
|
68
|
+
Merb::BootLoader.before_app_loads do
|
69
|
+
|
70
|
+
Merb::Slices::config[:thin_test_slice][:option] = value
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
file: config/router.rb
|
75
|
+
|
76
|
+
# example: /thin-test-slice/:controller/:action/:id
|
77
|
+
|
78
|
+
add_slice(:ThinTestSlice)
|
79
|
+
|
80
|
+
# example: /foo/:controller/:action/:id
|
81
|
+
|
82
|
+
add_slice(:ThinTestSlice, 'foo') # same as :path => 'foo'
|
83
|
+
|
84
|
+
# example: /:lang/:controller/:action/:id (with :a param set)
|
85
|
+
|
86
|
+
add_slice(:ThinTestSlice, :path => ':lang', :params => { :a => 'b' })
|
87
|
+
|
88
|
+
# example: /:controller/:action/:id
|
89
|
+
|
90
|
+
slice(:ThinTestSlice)
|
91
|
+
|
92
|
+
Normally you should also run the following rake task:
|
93
|
+
|
94
|
+
rake slices:thin_test_slice:install
|
95
|
+
|
96
|
+
------------------------------------------------------------------------------
|
97
|
+
|
98
|
+
About Slices
|
99
|
+
============
|
100
|
+
|
101
|
+
Merb-Slices is a Merb plugin for using and creating application 'slices' which
|
102
|
+
help you modularize your application. Usually these are reuseable extractions
|
103
|
+
from your main app. In effect, a Slice is just like a regular Merb MVC
|
104
|
+
application, both in functionality as well as in structure.
|
105
|
+
|
106
|
+
When you generate a Slice stub structure, a module is setup to serve as a
|
107
|
+
namespace for your controller, models, helpers etc. This ensures maximum
|
108
|
+
encapsulation. You could say a Slice is a mixture between a Merb plugin (a
|
109
|
+
Gem) and a Merb application, reaping the benefits of both.
|
110
|
+
|
111
|
+
A host application can 'mount' a Slice inside the router, which means you have
|
112
|
+
full over control how it integrates. By default a Slice's routes are prefixed
|
113
|
+
by its name (a router :namespace), but you can easily provide your own prefix
|
114
|
+
or leave it out, mounting it at the root of your url-schema. You can even
|
115
|
+
mount a Slice multiple times and give extra parameters to customize an
|
116
|
+
instance's behaviour.
|
117
|
+
|
118
|
+
A Slice's Application controller uses controller_for_slice to setup slice
|
119
|
+
specific behaviour, which mainly affects cascaded view handling. Additionaly,
|
120
|
+
this method is available to any kind of controller, so it can be used for
|
121
|
+
Merb Mailer too for example.
|
122
|
+
|
123
|
+
There are many ways which let you customize a Slice's functionality and
|
124
|
+
appearance without ever touching the Gem-level code itself. It's not only easy
|
125
|
+
to add template/layout overrides, you can also add/modify controllers, models
|
126
|
+
and other runtime code from within the host application.
|
127
|
+
|
128
|
+
To create your own Slice run this (somewhere outside of your merb app):
|
129
|
+
|
130
|
+
$ merb-gen slice <your-lowercase-slice-name>
|