Permalink
Browse files

initial slice generation

  • Loading branch information...
1 parent f6293e0 commit e26c1d883c55f7ddd934ae6e4c893f7f6853b3d7 @mattetti committed Oct 21, 2008
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Engine Yard
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
170 README
@@ -0,0 +1,170 @@
+MerbLatestRssItemsSlice
+=======================
+
+A slice for the Merb framework.
+
+------------------------------------------------------------------------------
+
+merb_latest_rss_items_slice
+|-- LICENSE
+|-- README
+|-- Rakefile [1]
+|-- TODO
+|-- app [2]
+| |-- controllers
+| | |-- application.rb
+| | `-- main.rb
+| |-- helpers
+| | `-- application_helper.rb
+| `-- views
+| |-- layout
+| | `-- merb_latest_rss_items_slice.html.erb [3]
+| `-- main
+| `-- index.html.erb
+|-- lib
+| |-- merb_latest_rss_items_slice
+| | |-- merbtasks.rb [4]
+| | `-- slicetasks.rb [5]
+| `-- merb_latest_rss_items_slice.rb [6]
+|-- log
+| `-- merb_test.log
+|-- public [7]
+| |-- javascripts
+| | `-- master.js
+| `-- stylesheets
+| `-- master.css
+|-- spec [8]
+| |-- merb_latest_rss_items_slice_spec.rb
+| |-- controllers
+| | `-- main_spec.rb
+| `-- spec_helper.rb
+`-- stubs [9]
+ `-- app
+ `-- controllers
+ |-- application.rb
+ `-- main.rb
+
+
+1. Rake tasks to package/install the gem - edit this to modify the manifest.
+2. The slice application: controllers, models, helpers, views.
+3. The default layout, as specified in Merb::Slices::config[:merb_latest_rss_items_slice][:layout]
+ change this to :application to use the app's layout.
+4. Standard rake tasks available to your application.
+5. Your custom application rake tasks.
+6. The main slice file - contains all slice setup logic/config.
+7. Public assets you (optionally) install using rake slices:merb_latest_rss_items_slice:install
+8. Specs for basis slice behaviour - you usually adapt these for your slice.
+9. Stubs of classes/views/files for the end-user to override - usually these
+ mimic the files in app/ and/or public/; use rake slices:merb_latest_rss_items_slice:stubs to
+ get started with the override stubs. Also, slices:merb_latest_rss_items_slice:patch will
+ copy over views to override in addition to the files found in /stubs.
+
+
+To see all available tasks for MerbLatestRssItemsSlice run:
+
+rake -T slices:merb_latest_rss_items_slice
+
+------------------------------------------------------------------------------
+
+Instructions for installation:
+
+file: config/init.rb
+
+# add the slice as a regular dependency
+
+dependency 'merb_latest_rss_items_slice'
+
+# if needed, configure which slices to load and in which order
+
+Merb::Plugins.config[:merb_slices] = { :queue => ["MerbLatestRssItemsSlice", ...] }
+
+# optionally configure the plugins in a before_app_loads callback
+
+Merb::BootLoader.before_app_loads do
+
+ Merb::Slices::config[:merb_latest_rss_items_slice][:option] = value
+
+end
+
+file: config/router.rb
+
+# example: /merb_latest_rss_items_slice/:controller/:action/:id
+
+add_slice(:MerbLatestRssItemsSlice)
+
+# example: /foo/:controller/:action/:id
+
+add_slice(:MerbLatestRssItemsSlice, 'foo') # same as :path => 'foo'
+
+# example: /:lang/:controller/:action/:id
+
+add_slice(:MerbLatestRssItemsSlice, :path => ':lang')
+
+# example: /:controller/:action/:id
+
+slice(:MerbLatestRssItemsSlice)
+
+Normally you should also run the following rake task:
+
+rake slices:merb_latest_rss_items_slice:install
+
+------------------------------------------------------------------------------
+
+You can put your application-level overrides in:
+
+host-app/slices/merb_latest_rss_items_slice/app - controllers, models, views ...
+
+Templates are located in this order:
+
+1. host-app/slices/merb_latest_rss_items_slice/app/views/*
+2. gems/merb_latest_rss_items_slice/app/views/*
+3. host-app/app/views/*
+
+You can use the host application's layout by configuring the
+merb_latest_rss_items_slice slice in a before_app_loads block:
+
+Merb::Slices.config[:merb_latest_rss_items_slice] = { :layout => :application }
+
+By default :merb_latest_rss_items_slice is used. If you need to override
+stylesheets or javascripts, just specify your own files in your layout
+instead/in addition to the ones supplied (if any) in
+host-app/public/slices/merb_latest_rss_items_slice.
+
+In any case don't edit those files directly as they may be clobbered any time
+rake merb_latest_rss_items_slice:install is run.
+
+------------------------------------------------------------------------------
+
+About Slices
+============
+
+Merb-Slices is a Merb plugin for using and creating application 'slices' which
+help you modularize your application. Usually these are reuseable extractions
+from your main app. In effect, a Slice is just like a regular Merb MVC
+application, both in functionality as well as in structure.
+
+When you generate a Slice stub structure, a module is setup to serve as a
+namespace for your controller, models, helpers etc. This ensures maximum
+encapsulation. You could say a Slice is a mixture between a Merb plugin (a
+Gem) and a Merb application, reaping the benefits of both.
+
+A host application can 'mount' a Slice inside the router, which means you have
+full over control how it integrates. By default a Slice's routes are prefixed
+by its name (a router :namespace), but you can easily provide your own prefix
+or leave it out, mounting it at the root of your url-schema. You can even
+mount a Slice multiple times and give extra parameters to customize an
+instance's behaviour.
+
+A Slice's Application controller uses controller_for_slice to setup slice
+specific behaviour, which mainly affects cascaded view handling. Additionaly,
+this method is available to any kind of controller, so it can be used for
+Merb Mailer too for example.
+
+There are many ways which let you customize a Slice's functionality and
+appearance without ever touching the Gem-level code itself. It's not only easy
+to add template/layout overrides, you can also add/modify controllers, models
+and other runtime code from within the host application.
+
+To create your own Slice run this (somewhere outside of your merb app):
+
+$ merb-gen slice <your-lowercase-slice-name>
View
@@ -0,0 +1,55 @@
+require 'rubygems'
+require 'rake/gempackagetask'
+
+require 'merb-core'
+require 'merb-core/tasks/merb'
+
+GEM_NAME = "merb_latest_rss_items_slice"
+AUTHOR = "Your Name"
+EMAIL = "Your Email"
+HOMEPAGE = "http://merbivore.com/"
+SUMMARY = "Merb Slice that provides ..."
+GEM_VERSION = "0.9.10"
+
+spec = Gem::Specification.new do |s|
+ s.rubyforge_project = 'merb'
+ s.name = GEM_NAME
+ s.version = GEM_VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
+ s.summary = SUMMARY
+ s.description = s.summary
+ s.author = AUTHOR
+ s.email = EMAIL
+ s.homepage = HOMEPAGE
+ s.add_dependency('merb-slices', '>= 0.9.10')
+ s.require_path = 'lib'
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
+end
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
+
+desc "Install the gem"
+task :install do
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
+end
+
+desc "Uninstall the gem"
+task :uninstall do
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
+end
+
+desc "Create a gemspec file"
+task :gemspec do
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
+ file.puts spec.to_ruby
+ end
+end
+
+require 'spec/rake/spectask'
+require 'merb-core/test/tasks/spectasks'
+desc 'Default: run spec examples'
+task :default => 'spec'
View
15 TODO
@@ -0,0 +1,15 @@
+TODO:
+
+- Fix MerbLatestRssItemsSlice.description and MerbLatestRssItemsSlice.version
+- Fix LICENSE with your name
+- Fix Rakefile with your name and contact info
+- Add your code to lib/merb_latest_rss_items_slice.rb
+- Add your Merb rake tasks to lib/merb_latest_rss_items_slice/merbtasks.rb
+
+Remove anything that you don't need:
+
+- app/controllers/main.rb MerbLatestRssItemsSlice::Main controller
+- app/views/layout/merb_latest_rss_items_slice.html.erb
+- spec/controllers/main_spec.rb controller specs
+- public/* any public files
+- stubs/* any stub files
@@ -0,0 +1,5 @@
+class MerbLatestRssItemsSlice::Application < Merb::Controller
+
+ controller_for_slice
+
+end
View
@@ -0,0 +1,7 @@
+class MerbLatestRssItemsSlice::Main < MerbLatestRssItemsSlice::Application
+
+ def index
+ render
+ end
+
+end
@@ -0,0 +1,64 @@
+module Merb
+ module MerbLatestRssItemsSlice
+ module ApplicationHelper
+
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path relative to the public directory, with added segments.
+ def image_path(*segments)
+ public_path_for(:image, *segments)
+ end
+
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path relative to the public directory, with added segments.
+ def javascript_path(*segments)
+ public_path_for(:javascript, *segments)
+ end
+
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path relative to the public directory, with added segments.
+ def stylesheet_path(*segments)
+ public_path_for(:stylesheet, *segments)
+ end
+
+ # Construct a path relative to the public directory
+ #
+ # @param <Symbol> The type of component.
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path relative to the public directory, with added segments.
+ def public_path_for(type, *segments)
+ ::MerbLatestRssItemsSlice.public_path_for(type, *segments)
+ end
+
+ # Construct an app-level path.
+ #
+ # @param <Symbol> The type of component.
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path within the host application, with added segments.
+ def app_path_for(type, *segments)
+ ::MerbLatestRssItemsSlice.app_path_for(type, *segments)
+ end
+
+ # Construct a slice-level path.
+ #
+ # @param <Symbol> The type of component.
+ # @param *segments<Array[#to_s]> Path segments to append.
+ #
+ # @return <String>
+ # A path within the slice source (Gem), with added segments.
+ def slice_path_for(type, *segments)
+ ::MerbLatestRssItemsSlice.slice_path_for(type, *segments)
+ end
+
+ end
+ end
+end
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>Fresh MerbLatestRssItemsSlice Slice</title>
+ <link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
+ <script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
+ </head>
+ <!-- you can override this layout at slices/merb_latest_rss_items_slice/app/views/layout/merb_latest_rss_items_slice.html.erb -->
+ <body class="merb_latest_rss_items_slice-slice">
+ <div id="container">
+ <h1>MerbLatestRssItemsSlice Slice</h1>
+ <div id="main"><%= catch_content :for_layout %></div>
+ </div>
+ </body>
+</html>
@@ -0,0 +1 @@
+<strong><%= slice.description %></strong> (v. <%= slice.version %>)
Oops, something went wrong.

0 comments on commit e26c1d8

Please sign in to comment.