├── README
├── merb_sequel
├── spec
│ ├── .gitignore
│ ├── spec_controller.rb
│ ├── config
│ │ └── database.yml
│ ├── merb_sequel_spec.rb
│ ├── sequel_ext_spec.rb
│ ├── spec_model.rb
│ ├── spec_helper.rb
│ └── merb_sequel_session_spec.rb
├── TODO
├── lib
│ ├── sequel_ext
│ │ └── model.rb
│ ├── generators
│ │ ├── templates
│ │ │ ├── model
│ │ │ │ └── app
│ │ │ │ │ └── models
│ │ │ │ │ └── %file_name%.rb
│ │ │ ├── resource_controller
│ │ │ │ └── app
│ │ │ │ │ ├── views
│ │ │ │ │ └── %file_name%
│ │ │ │ │ │ ├── new.html.erb
│ │ │ │ │ │ ├── edit.html.erb
│ │ │ │ │ │ ├── show.html.erb
│ │ │ │ │ │ └── index.html.erb
│ │ │ │ │ └── controllers
│ │ │ │ │ └── %file_name%.rb
│ │ │ ├── session_migration
│ │ │ │ └── schema
│ │ │ │ │ └── migrations
│ │ │ │ │ └── %version%_sessions.rb
│ │ │ └── migration
│ │ │ │ └── schema
│ │ │ │ └── migrations
│ │ │ │ └── %file_name%.rb
│ │ ├── migration.rb
│ │ ├── session_migration.rb
│ │ ├── model.rb
│ │ └── resource_controller.rb
│ ├── merb
│ │ ├── orms
│ │ │ └── sequel
│ │ │ │ ├── database.yml.sample
│ │ │ │ └── connection.rb
│ │ └── session
│ │ │ └── sequel_session.rb
│ ├── merb_sequel.rb
│ └── merb_sequel
│ │ └── merbtasks.rb
├── Generators
├── LICENSE
├── README
└── Rakefile
├── merb_screw_unit
├── public
│ ├── javascripts
│ │ ├── master.js
│ │ ├── application.js
│ │ ├── jquery.fn.js
│ │ ├── screw.events.js
│ │ ├── screw.mock.js
│ │ ├── screw.builder.js
│ │ ├── screw.behaviors.js
│ │ ├── jquery.print.js
│ │ ├── screw.matchers.js
│ │ ├── metadata.jquery.js
│ │ └── livequery.jquery.js
│ └── stylesheets
│ │ ├── master.css
│ │ └── screw.css
├── stubs
│ └── app
│ │ └── controllers
│ │ ├── main.rb
│ │ └── application.rb
├── app
│ ├── views
│ │ ├── main
│ │ │ └── index.html.erb
│ │ └── layout
│ │ │ └── merb_screw_unit.html.erb
│ ├── controllers
│ │ ├── application.rb
│ │ └── main.rb
│ └── helpers
│ │ └── application_helper.rb
├── TODO
├── lib
│ ├── merb_screw_unit
│ │ ├── slicetasks.rb
│ │ └── merbtasks.rb
│ └── merb_screw_unit.rb
├── LICENSE
├── spec
│ ├── spec_helper.rb
│ ├── controllers
│ │ └── main_spec.rb
│ └── merb_screw_unit_spec.rb
├── Rakefile
├── readme.markdown
└── README
├── merb_parts
├── spec
│ ├── fixtures
│ │ ├── parts
│ │ │ ├── views
│ │ │ │ ├── todo_part
│ │ │ │ │ ├── formatted_output.html.erb
│ │ │ │ │ ├── formatted_output.js.erb
│ │ │ │ │ ├── formatted_output.xml.erb
│ │ │ │ │ ├── list.html.erb
│ │ │ │ │ └── part_with_params.html.erb
│ │ │ │ └── layout
│ │ │ │ │ ├── todo_part.html.erb
│ │ │ │ │ └── todo_part.xml.erb
│ │ │ ├── done_part.rb
│ │ │ └── todo_part.rb
│ │ ├── views
│ │ │ └── main
│ │ │ │ └── part_within_view.html.erb
│ │ └── controllers
│ │ │ └── main.rb
│ ├── spec_helper.rb
│ └── merb-parts_spec.rb
├── README
├── lib
│ ├── merb_parts
│ │ ├── merbtasks.rb
│ │ ├── mixins
│ │ │ ├── web_controller.rb
│ │ │ └── parts_mixin.rb
│ │ └── part_controller.rb
│ └── merb_parts.rb
├── TODO
├── LICENSE
└── Rakefile
├── merb_builder
├── lib
│ ├── merb_builder.rb
│ └── merb_builder
│ │ └── template.rb
├── spec
│ ├── controllers
│ │ ├── views
│ │ │ ├── partial_builder
│ │ │ │ ├── _partial_builder.xml.builder
│ │ │ │ └── index.xml.builder
│ │ │ ├── partial_ivars
│ │ │ │ ├── _partial_builder.xml.builder
│ │ │ │ └── index.xml.builder
│ │ │ ├── builder_controller
│ │ │ │ └── index.xml.builder
│ │ │ ├── builder_config
│ │ │ │ └── index.xml.builder
│ │ │ ├── concat_builder
│ │ │ │ └── index.xml.builder
│ │ │ └── capture_builder
│ │ │ │ └── index.xml.builder
│ │ └── builder.rb
│ ├── spec_helper.rb
│ └── builder_spec.rb
├── README
├── TODO
├── LICENSE
└── Rakefile
├── merb_stories
├── lib
│ ├── generators
│ │ ├── templates
│ │ │ ├── story
│ │ │ │ ├── step.rbt
│ │ │ │ ├── story.t
│ │ │ │ └── story.rbt
│ │ │ └── merb_story_setup
│ │ │ │ └── stories
│ │ │ │ ├── stories
│ │ │ │ └── all.rb
│ │ │ │ └── helper.rb
│ │ ├── merb_story_setup.rb
│ │ └── story.rb
│ ├── merb_stories
│ │ ├── merbtasks.rb
│ │ └── story.rb
│ └── merb_stories.rb
├── Generators
├── TODO
├── LICENSE
├── README
└── Rakefile
├── merb_test_unit
├── specs
│ ├── hpricot_asserts_spec.rb
│ ├── spec_helper.rb
│ └── controller_asserts_spec.rb
├── README
├── TODO
├── lib
│ ├── merb_test_unit
│ │ └── merbtasks.rb
│ ├── merb_test_unit.rb
│ └── asserts
│ │ ├── controller_asserts.rb
│ │ └── hpricot_asserts.rb
├── LICENSE
└── Rakefile
├── merb_laszlo
├── README
├── lib
│ ├── merb-laszlo
│ │ ├── merbtasks.rb
│ │ ├── controllers.rb
│ │ └── helpers.rb
│ └── merb-laszlo.rb
├── spec
│ ├── controllers
│ │ └── laszlo_controller.rb
│ ├── laszlo_module_spec.rb
│ ├── merb_laszlo_spec.rb
│ └── spec_helper.rb
├── LICENSE
├── merb-laszlo.gemspec
└── Rakefile
├── merb_activerecord
├── specs
│ ├── spec_helper.rb
│ ├── merb_active_record_session_spec.rb
│ └── merb_active_record_spec.rb
├── lib
│ ├── generators
│ │ ├── templates
│ │ │ ├── model
│ │ │ │ └── app
│ │ │ │ │ └── models
│ │ │ │ │ └── %file_name%.rb
│ │ │ ├── resource_controller
│ │ │ │ └── app
│ │ │ │ │ ├── views
│ │ │ │ │ └── %file_name%
│ │ │ │ │ │ ├── edit.html.erb
│ │ │ │ │ │ ├── new.html.erb
│ │ │ │ │ │ ├── show.html.erb
│ │ │ │ │ │ └── index.html.erb
│ │ │ │ │ └── controllers
│ │ │ │ │ └── %file_name%.rb
│ │ │ ├── migration
│ │ │ │ └── schema
│ │ │ │ │ └── migrations
│ │ │ │ │ └── %file_name%.rb
│ │ │ └── session_migration
│ │ │ │ └── schema
│ │ │ │ └── migrations
│ │ │ │ └── %version%_database_sessions.rb
│ │ ├── migration.rb
│ │ ├── session_migration.rb
│ │ ├── model.rb
│ │ └── resource_controller.rb
│ ├── merb
│ │ ├── orms
│ │ │ └── active_record
│ │ │ │ ├── cleanup.rb
│ │ │ │ ├── database.yml.sample
│ │ │ │ └── connection.rb
│ │ └── session
│ │ │ └── active_record_session.rb
│ └── merb_activerecord.rb
├── TODO
├── Generators
├── README
├── LICENSE
└── Rakefile
├── .gitignore
├── merb_jquery
├── TODO
├── README
├── lib
│ ├── merb_jquery
│ │ └── merbtasks.rb
│ └── merb_jquery.rb
├── LICENSE
└── Rakefile
├── release_plugins
├── Rakefile
└── CHANGELOG
/README:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/merb_sequel/spec/.gitignore:
--------------------------------------------------------------------------------
1 | test.db
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/master.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/application.js:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/todo_part/formatted_output.html.erb:
--------------------------------------------------------------------------------
1 | part_html_format
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/todo_part/formatted_output.js.erb:
--------------------------------------------------------------------------------
1 | part_js_format
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb:
--------------------------------------------------------------------------------
1 | part_xml_format
--------------------------------------------------------------------------------
/merb_builder/lib/merb_builder.rb:
--------------------------------------------------------------------------------
1 | require "builder"
2 | require "merb_builder/template"
3 |
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/views/main/part_within_view.html.erb:
--------------------------------------------------------------------------------
1 | <%= part TodoPart => :one %>
--------------------------------------------------------------------------------
/merb_stories/lib/generators/templates/story/step.rbt:
--------------------------------------------------------------------------------
1 | steps_for(:<%= step_name %>) do
2 |
3 | end
--------------------------------------------------------------------------------
/merb_test_unit/specs/hpricot_asserts_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/partial_builder/_partial_builder.xml.builder:
--------------------------------------------------------------------------------
1 | xml.hello world
2 |
--------------------------------------------------------------------------------
/merb_parts/README:
--------------------------------------------------------------------------------
1 | merb-parts
2 | ==========
3 |
4 | A plugin for the Merb framework that provides ...
--------------------------------------------------------------------------------
/merb_builder/README:
--------------------------------------------------------------------------------
1 | merb-builder
2 | =========
3 |
4 | A plugin for the Merb framework that provides ...
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/partial_ivars/_partial_builder.xml.builder:
--------------------------------------------------------------------------------
1 | xml.p "#{@var1} #{@var2}"
2 |
--------------------------------------------------------------------------------
/merb_screw_unit/stubs/app/controllers/main.rb:
--------------------------------------------------------------------------------
1 | class MerbScrewUnit::Main < MerbScrewUnit::Application
2 | end
--------------------------------------------------------------------------------
/merb_test_unit/README:
--------------------------------------------------------------------------------
1 | merb-rspec
2 | =========
3 |
4 | A plugin for the Merb framework that provides ...
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/builder_controller/index.xml.builder:
--------------------------------------------------------------------------------
1 | xml.instruct!
2 | xml.hello 'World'
3 |
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/todo_part/list.html.erb:
--------------------------------------------------------------------------------
1 | TODOPART
2 | <%= @todos.join('|') %>
3 | TODOPART
--------------------------------------------------------------------------------
/merb_screw_unit/app/views/main/index.html.erb:
--------------------------------------------------------------------------------
1 | <%= slice.description %> (v. <%= slice.version %>)
--------------------------------------------------------------------------------
/merb_screw_unit/stubs/app/controllers/application.rb:
--------------------------------------------------------------------------------
1 | class MerbScrewUnit::Application < Merb::Controller
2 | end
--------------------------------------------------------------------------------
/merb_laszlo/README:
--------------------------------------------------------------------------------
1 | merb-laszlo
2 | ===========
3 |
4 | A plugin for the Merb framework that provides support for Laszlo
--------------------------------------------------------------------------------
/merb_sequel/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | * Figure out why using a sqlite3 memory store for the session bombs with stream errors.
3 |
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/layout/todo_part.html.erb:
--------------------------------------------------------------------------------
1 | TODOLAYOUT
2 | <%= catch_content :for_layout %>
3 | TODOLAYOUT
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/views/layout/todo_part.xml.erb:
--------------------------------------------------------------------------------
1 |
2 | <%= catch_content :for_layout %>
3 |
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/builder_config/index.xml.builder:
--------------------------------------------------------------------------------
1 | xml.instruct!
2 | xml.foo do
3 | xml.bar "baz"
4 | end
5 |
--------------------------------------------------------------------------------
/merb_parts/spec/fixtures/parts/done_part.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) / 'todo_part'
2 |
3 | class DonePart < TodoPart
4 | end
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/partial_builder/index.xml.builder:
--------------------------------------------------------------------------------
1 | xml.instruct!
2 | xml << partial(:partial_builder, :world => "World")
3 |
--------------------------------------------------------------------------------
/merb_sequel/lib/sequel_ext/model.rb:
--------------------------------------------------------------------------------
1 | module Sequel
2 | class Model
3 | def new_record?
4 | self.new?
5 | end
6 | end
7 | end
--------------------------------------------------------------------------------
/merb_activerecord/specs/spec_helper.rb:
--------------------------------------------------------------------------------
1 | $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2 | require 'merb-core'
3 | require 'merb_activerecord'
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/partial_ivars/index.xml.builder:
--------------------------------------------------------------------------------
1 | @var2 = "Builder"
2 | xml.instruct!
3 | xml << partial(:partial_builder)
4 |
--------------------------------------------------------------------------------
/merb_screw_unit/app/controllers/application.rb:
--------------------------------------------------------------------------------
1 | class MerbScrewUnit::Application < Merb::Controller
2 |
3 | controller_for_slice
4 |
5 | end
--------------------------------------------------------------------------------
/merb_screw_unit/app/controllers/main.rb:
--------------------------------------------------------------------------------
1 | class MerbScrewUnit::Main < MerbScrewUnit::Application
2 |
3 | def index
4 | render
5 | end
6 |
7 | end
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | test_log
3 | pkg
4 | pkg/*
5 | */pkg/*
6 | *.log
7 | log
8 | !log*.rb
9 | */log
10 | log/*
11 | */log/*
12 | coverage
13 | */coverage
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/concat_builder/index.xml.builder:
--------------------------------------------------------------------------------
1 | xml.instruct!
2 | concatter do
3 | xml.comment!('I would not do that if I were you')
4 | end
5 |
--------------------------------------------------------------------------------
/merb_sequel/lib/generators/templates/model/app/models/%file_name%.rb:
--------------------------------------------------------------------------------
1 | <% with_modules(modules) do -%>
2 | class <%= class_name %> < Sequel::Model
3 | end
4 | <% end -%>
--------------------------------------------------------------------------------
/merb_stories/lib/generators/templates/story/story.t:
--------------------------------------------------------------------------------
1 | Story: Some story about <%= story_name %>
2 |
3 | As a ...
4 | I want to ...
5 | So that ...
6 |
7 | Scenario: ...
--------------------------------------------------------------------------------
/merb_activerecord/lib/generators/templates/model/app/models/%file_name%.rb:
--------------------------------------------------------------------------------
1 | <% with_modules(modules) do -%>
2 | class <%= class_name %> < ActiveRecord::Base
3 | end
4 | <% end -%>
5 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/stylesheets/master.css:
--------------------------------------------------------------------------------
1 | html, body { margin: 0; padding: 0; }
2 | #container { width: 800px; margin: 4em auto; padding: 4em 4em 6em 4em; background: #DDDDDD; }
--------------------------------------------------------------------------------
/merb_parts/lib/merb_parts/merbtasks.rb:
--------------------------------------------------------------------------------
1 | namespace :merb-parts do
2 | desc "Do something for merb-parts"
3 | task :default do
4 | puts "merb-parts doesn't do anything"
5 | end
6 | end
--------------------------------------------------------------------------------
/merb_sequel/spec/spec_controller.rb:
--------------------------------------------------------------------------------
1 | class SpecController < Merb::Controller
2 | def set
3 | session[:key] = 'value'
4 | end
5 |
6 | def get
7 | session[:key]
8 | end
9 | end
--------------------------------------------------------------------------------
/merb_stories/Generators:
--------------------------------------------------------------------------------
1 | scope 'merb-gen' do
2 | dir = File.join(File.dirname(__FILE__), 'lib', 'generators/')
3 | Merb.add_generators dir + 'merb_story_setup', dir + 'story'
4 | end
5 |
--------------------------------------------------------------------------------
/merb_jquery/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb-haml.rb
5 | Add your Merb rake tasks to lib/merb-haml/merbtasks.rb
--------------------------------------------------------------------------------
/merb_laszlo/lib/merb-laszlo/merbtasks.rb:
--------------------------------------------------------------------------------
1 | namespace :merb-laszlo do
2 | desc "Do something for merb-laszlo"
3 | task :default do
4 | puts "merb-laszlo doesn't do anything"
5 | end
6 | end
--------------------------------------------------------------------------------
/merb_laszlo/spec/controllers/laszlo_controller.rb:
--------------------------------------------------------------------------------
1 | class LaszloController < Merb::Controller
2 |
3 | def index
4 | laszlo("")
5 | end
6 |
7 | end
--------------------------------------------------------------------------------
/merb_stories/lib/generators/templates/merb_story_setup/stories/stories/all.rb:
--------------------------------------------------------------------------------
1 | dir = File.dirname(__FILE__)
2 | Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
3 | require file
4 | end
--------------------------------------------------------------------------------
/merb_builder/spec/controllers/views/capture_builder/index.xml.builder:
--------------------------------------------------------------------------------
1 | xml.instruct!
2 | @foo = capture do
3 | xml.comment!('I would not say such things if I were you')
4 | end
5 | xml.node 'Capture'
--------------------------------------------------------------------------------
/merb_parts/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb-parts.rb
5 | Add your Merb rake tasks to lib/merb-parts/merbtasks.rb
--------------------------------------------------------------------------------
/merb_stories/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb-rspec.rb
5 | Add your Merb rake tasks to lib/merb-rspec/merbtasks.rb
--------------------------------------------------------------------------------
/merb_stories/lib/merb_stories/merbtasks.rb:
--------------------------------------------------------------------------------
1 | desc "Run the given story. rake story[story_name]"
2 | task :story, :story_name do |t,args|
3 | sh %{ruby stories/stories/#{args.story_name}.rb}
4 | end
--------------------------------------------------------------------------------
/merb_test_unit/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb-rspec.rb
5 | Add your Merb rake tasks to lib/merb-rspec/merbtasks.rb
--------------------------------------------------------------------------------
/merb_builder/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb-builder.rb
5 | Add your Merb rake tasks to lib/merb-builder/merbtasks.rb
--------------------------------------------------------------------------------
/merb_activerecord/TODO:
--------------------------------------------------------------------------------
1 | TODO:
2 | Fix LICENSE with your name
3 | Fix Rakefile with your name and contact info
4 | Add your code to lib/merb_active_record.rb
5 | Add your Merb rake tasks to lib/merb_active_record/merbtasks.rb
--------------------------------------------------------------------------------
/merb_sequel/lib/generators/templates/resource_controller/app/views/%file_name%/new.html.erb:
--------------------------------------------------------------------------------
1 |
, [">= 0.9.0"])
22 | end
23 |
--------------------------------------------------------------------------------
/merb_sequel/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2007-2008,
2 | Duane Johnson, Wayne E. Seguin, Lance Carlson, Michael S. Klishin.
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/merb_parts/lib/merb_parts/mixins/web_controller.rb:
--------------------------------------------------------------------------------
1 | # Includes files into the class to allow it to minimally delegates to a web controller
2 | module Merb
3 | module Mixins
4 | module WebController
5 |
6 | def self.included(base)
7 | [:content_type, :web_controller].each do |attr|
8 | base.send(:attr_accessor, attr)
9 | end
10 | base.send(:include, InstanceMethods)
11 | base.send(:extend, ClassMethods)
12 | end
13 |
14 | module InstanceMethods
15 | def request
16 | @web_controller.request
17 | end
18 |
19 | def cookies
20 | @web_controller.cookies
21 | end
22 |
23 | def headers
24 | @web_controller.headers
25 | end
26 |
27 | def session
28 | @web_controller.session
29 | end
30 |
31 | def response
32 | @web_controller.response
33 | end
34 |
35 | def route
36 | request.route
37 | end
38 |
39 | def url(name, *args)
40 | @web_controller.url(name, *args)
41 | end
42 |
43 | end
44 |
45 | module ClassMethods
46 |
47 | end
48 |
49 |
50 |
51 | end # WebController
52 | end # Mixins
53 | end # Merb
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/screw.events.js:
--------------------------------------------------------------------------------
1 | (function($) {
2 | $(Screw)
3 | .bind('loaded', function() {
4 | $('.describe, .it')
5 | .click(function() {
6 | document.location = location.href.split('?')[0] + '?' + $(this).fn('selector');
7 | return false;
8 | })
9 | .focus(function() {
10 | return $(this).addClass('focused');
11 | })
12 | .bind('scroll', function() {
13 | document.body.scrollTop = $(this).offset().top;
14 | });
15 |
16 | $('.it')
17 | .bind('enqueued', function() {
18 | $(this).addClass('enqueued');
19 | })
20 | .bind('running', function() {
21 | $(this).addClass('running');
22 | })
23 | .bind('passed', function() {
24 | $(this).addClass('passed');
25 | })
26 | .bind('failed', function(e, reason) {
27 | reasonText = "" + reason.toString() + "
";
28 | if(reason.stack) reasonText += ("" + reason.stack + "
");
29 | $(this)
30 | .addClass('failed')
31 | .append($('').html(reasonText));
32 | })
33 | })
34 | .bind('before', function() {
35 | $('.status').text('Running...');
36 | })
37 | .bind('after', function() {
38 | $('.status').fn('display')
39 | })
40 | })(jQuery);
--------------------------------------------------------------------------------
/merb_sequel/lib/merb_sequel.rb:
--------------------------------------------------------------------------------
1 | if defined?(Merb::Plugins)
2 | Merb::Plugins.config[:merb_sequel] = {}
3 | require File.join(File.dirname(__FILE__) / "sequel_ext" / "model")
4 | require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "connection")
5 | Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
6 |
7 | class Merb::Orms::Sequel::Connect < Merb::BootLoader
8 |
9 | after BeforeAppLoads
10 |
11 | def self.run
12 | Merb::Orms::Sequel.connect
13 | if Merb::Config.session_stores.include?(:sequel)
14 | Merb.logger.debug "Using Sequel sessions"
15 | require File.join(File.dirname(__FILE__) / "merb" / "session" / "sequel_session")
16 | end
17 |
18 | Merb::Router.root_behavior = Merb::Router.root_behavior.identify(Sequel::Model => :pk)
19 | end
20 |
21 | end
22 |
23 | class Merb::Orms::Sequel::DisconnectBeforeFork < Merb::BootLoader
24 | after AfterAppLoads
25 |
26 | def self.run
27 | Merb.logger.debug "Disconnecting database connection before forking."
28 | ::Sequel::DATABASES.each { |db| db.disconnect }
29 | end
30 |
31 | end
32 |
33 | generators = File.join(File.dirname(__FILE__), 'generators')
34 | Merb.add_generators generators / :migration
35 | Merb.add_generators generators / :model
36 | Merb.add_generators generators / :resource_controller
37 | Merb.add_generators generators / :session_migration
38 |
39 | end
--------------------------------------------------------------------------------
/merb_parts/lib/merb_parts/mixins/parts_mixin.rb:
--------------------------------------------------------------------------------
1 | module Merb
2 | module PartsMixin
3 |
4 | # Dispatches a PartController.
5 | # ==== Parameters
6 | # opts:: A Hash of Options. (see below)
7 | #
8 | # ==== Options
9 | # An option hash has two parts.
10 | # 1. keys that are Merb::PartControllers with values that are action names (as symbols)
11 | # 2. key value pairs that will become available in the PartController as params merged
12 | # with the web controllers params
13 | #
14 | # ==== Example
15 | # Calling a part controller
16 | # {{{
17 | # part TodoPart => :list
18 | # }}}
19 | #
20 | # Calling a part with additional options
21 | # {{{
22 | # part TodoPart => :list, :limit => 20, :user => current_user
23 | # }}}
24 | #
25 | # ==== Returns
26 | # Returns the result of the PartControllers action, which is a string.
27 | def part(opts = {})
28 | # Extract any params out that may have been specified
29 | klasses, opts = opts.partition do |k,v|
30 | k.respond_to?(:ancestors) && k.ancestors.include?(Merb::PartController)
31 | end
32 |
33 | opts = opts.empty? ? {} : Hash[*(opts.first)]
34 |
35 | res = klasses.inject([]) do |memo,(klass,action)|
36 | memo << klass.new(self, opts)._dispatch(action)
37 | end
38 | res.size == 1 ? res[0] : res
39 | end
40 |
41 | end
42 | end
--------------------------------------------------------------------------------
/merb_sequel/README:
--------------------------------------------------------------------------------
1 | = merb_sequel
2 |
3 | A plugin for the Merb framework that provides support for Sequel models.
4 |
5 |
6 | = Connection options
7 |
8 | Merb Sequel plugin uses config/database.yml for connection configuration.
9 |
10 | Options are:
11 |
12 | * adapter. :sqlite is assumed by default.
13 | * host. localhost is assumed by default.
14 | * username or user, default is an empty string
15 | * database, default is "hey_dude_configure_your_database". This should be
16 | either :memory: or file path for SQLite.
17 | * encoding or charset, default is utf8.
18 | * password. WARNING: default password is an empty string.
19 | * db_type: default is nil. Use "mssql" to connect to MSSQL using ODBC.
20 |
21 |
22 | = Generators
23 |
24 | After you install the plugin, merb-gen can generate Sequel models for you:
25 |
26 | merb-gen model --orm=sequel Article
27 |
28 | same with resources
29 |
30 | merb-gen resource --orm=sequel Article
31 |
32 |
33 | Note that if you have specified that you use Sequel in init.rb or environment
34 | specific init file (for instance, environments/development.rb)
35 | via use_orm :sequel, you need no specify --orm option explicitly when
36 | using merb-gen.
37 |
38 |
39 | = Contributors
40 |
41 | Originally written by Duane Johnson (canadaduane@gmail.com).
42 |
43 | Contributions by:
44 | * Wayne E. Seguin
45 | * Lance Carlson
46 | * Jacob Dunphy
47 | * Lori Holden
48 |
49 | Maintained by Michael S. Klishin (michael at novemberain.com)
50 |
--------------------------------------------------------------------------------
/merb_screw_unit/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'merb-core'
3 | require 'merb-slices'
4 | require 'spec'
5 |
6 | # Add merb_screw_unit.rb to the search path
7 | Merb::Plugins.config[:merb_slices][:auto_register] = true
8 | Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb_screw_unit.rb')
9 |
10 | # Using Merb.root below makes sure that the correct root is set for
11 | # - testing standalone, without being installed as a gem and no host application
12 | # - testing from within the host application; its root will be used
13 | Merb.start_environment(
14 | :testing => true,
15 | :adapter => 'runner',
16 | :environment => ENV['MERB_ENV'] || 'test',
17 | :merb_root => Merb.root,
18 | :session_store => 'memory'
19 | )
20 |
21 | module Merb
22 | module Test
23 | module SliceHelper
24 |
25 | # The absolute path to the current slice
26 | def current_slice_root
27 | @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
28 | end
29 |
30 | # Whether the specs are being run from a host application or standalone
31 | def standalone?
32 | Merb.root == ::MerbScrewUnit.root
33 | end
34 |
35 | end
36 | end
37 | end
38 |
39 | Spec::Runner.configure do |config|
40 | config.include(Merb::Test::ViewHelper)
41 | config.include(Merb::Test::RouteHelper)
42 | config.include(Merb::Test::ControllerHelper)
43 | config.include(Merb::Test::SliceHelper)
44 | end
--------------------------------------------------------------------------------
/merb_screw_unit/app/views/layout/merb_screw_unit.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%= js_include_tag "jquery-1.2.3", "jquery.fn", "jquery.print", "screw.builder",
4 | "screw.matchers", "screw.events", "screw.behaviors",
5 | "screw.mock" %>
6 |
7 | <%= css_include_tag "screw.css" %>
8 |
9 |
10 |
11 |
39 |
40 |
--------------------------------------------------------------------------------
/merb_test_unit/lib/asserts/controller_asserts.rb:
--------------------------------------------------------------------------------
1 | module Merb::Test::Unit::ControllerAsserts
2 | include Test::Unit::Assertions
3 | include Merb::Test::ControllerHelper
4 |
5 | def assert_redirect(target)
6 | assert([307, *(300..305)].include?(target.respond_to?(:status) ? target.status : target), redirect_failure_message(target))
7 | end
8 |
9 | def assert_redirect_to(expected, target)
10 | location = target.headers['Location']
11 |
12 | assert_redirect(target)
13 | assert_equal(expected, location, redirect_to_failure_message(expected, location))
14 | end
15 |
16 | def assert_success(target)
17 | assert((200..207).include?(target.respond_to?(:status) ? target.status : target), success_failure_message(target))
18 | end
19 |
20 | def assert_missing(target)
21 | assert((400..417).include?(target.respond_to?(:status) ? target.status : target), missing_failure_message(target))
22 | end
23 |
24 | private
25 | def redirect_failure_message(target)
26 | "expected#{target_message(target)} to redirect"
27 | end
28 |
29 | def redirect_to_failure_message(expected, location)
30 | "expected a redirect to <#{expected}>, but found one to #{location}"
31 | end
32 |
33 | def success_failure_message(target)
34 | "expected#{target_message(target)} to be successful"
35 | end
36 |
37 | def missing_failure_message(target)
38 | "expected#{target_message(target)} to be missing"
39 | end
40 |
41 | def target_message(target)
42 | " #{@target.inspect}" if target.respond_to?(:status)
43 | end
44 | end
--------------------------------------------------------------------------------
/merb_activerecord/lib/merb_activerecord.rb:
--------------------------------------------------------------------------------
1 | if defined?(Merb::Plugins)
2 |
3 | dependency "activerecord"
4 |
5 | require File.join(File.dirname(__FILE__) / "merb" / "orms" / "active_record" / "cleanup" )
6 | require File.join(File.dirname(__FILE__) / "merb" / "orms" / "active_record" / "connection")
7 | Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__) / "active_record" / "merbtasks"))
8 |
9 | class Merb::Orms::ActiveRecord::Connect < Merb::BootLoader
10 | after BeforeAppLoads
11 |
12 | def self.run
13 | Merb::Orms::ActiveRecord.connect
14 | if Merb::Config.session_stores.include?(:activerecord)
15 | Merb.logger.debug "Using ActiveRecord sessions"
16 | require File.join(File.dirname(__FILE__) / "merb" / "session" / "active_record_session")
17 | end
18 | # The default identify is :id instead of :to_param so that the identify
19 | # can be used as the default resource key
20 | Merb::Router.root_behavior = Merb::Router.root_behavior.identify(ActiveRecord::Base => :id)
21 | end
22 |
23 | end
24 |
25 | class Merb::Orms::ActiveRecord::DisconnectBeforeFork < Merb::BootLoader
26 | after AfterAppLoads
27 |
28 | def self.run
29 | Merb.logger.debug "Disconnecting database connection before forking."
30 | ::ActiveRecord::Base.clear_active_connections!
31 | end
32 | end
33 |
34 |
35 | generators = File.join(File.dirname(__FILE__), 'generators')
36 | Merb.add_generators generators / :migration
37 | Merb.add_generators generators / :model
38 | Merb.add_generators generators / :resource_controller
39 | Merb.add_generators generators / :session_migration
40 |
41 | end
--------------------------------------------------------------------------------
/merb_stories/lib/generators/story.rb:
--------------------------------------------------------------------------------
1 | module Merb::Generators
2 |
3 | class StoryGenerator < Generator
4 |
5 | desc <<-DESC
6 | Generates a plain text story
7 | DESC
8 |
9 | unless File.exists?('stories/stories/all.rb')
10 | invoke :merb_story_setup
11 | end
12 |
13 | first_argument :name, :required => true
14 |
15 | def split_name
16 | @split_name ||= name.split("/")
17 | end
18 |
19 | def story_name
20 | @story_name ||= split_name.pop
21 | end
22 |
23 | def story_path
24 | story_name
25 | @story_path ||= split_name.empty? ? nil : split_name.join("/")
26 | end
27 |
28 | def step_name
29 | story_path.nil? ? story_name : (story_path.gsub("/","_") + "_" + story_name)
30 | end
31 |
32 | def path_levels
33 | story_path.nil? ? 0 : story_path.split("/").size
34 | end
35 |
36 | def full_story_path
37 | story_path.nil? ? story_name : File.join(story_path, story_name)
38 | end
39 |
40 | def template_dir
41 | File.join(File.expand_path(File.dirname(__FILE__)), 'templates', 'story')
42 | end
43 |
44 | template :story do |t|
45 | t.source = File.join(template_dir, 'story.t')
46 | t.destination = 'stories/stories/' + full_story_path
47 | end
48 |
49 | template :story_rb do |t|
50 | t.source = File.join(template_dir, 'story.rbt')
51 | t.destination = 'stories/stories/' + full_story_path + '.rb'
52 | end
53 |
54 | template :step do |t|
55 | t.source = File.join(template_dir, 'step.rbt')
56 | t.destination = 'stories/steps/' + step_name + '.rb'
57 | end
58 | end
59 |
60 | add :story, StoryGenerator
61 | end
62 |
--------------------------------------------------------------------------------
/merb_stories/README:
--------------------------------------------------------------------------------
1 | merb_stories
2 | =========
3 |
4 | A plugin for the Merb framework that provides helper functionality for running stories in the rSpec testing framework.
5 |
6 |
7 | == Stories
8 | merb_stories supports rSpec story generation for regular Merb apps. See http://rspec.info for more information
9 | on using rSpec plain text stories.
10 |
11 | When using the generators for the first time, a few extra helper files will be generated.
12 |
13 | === Generation Examples
14 |
15 | ==== Simple
16 | To generate a simple story use:
17 |
18 | {{{merb-gen story my_story}}}
19 |
20 | This will generate all files needed to support that story.
21 | - steps/my_story.rb
22 | - stories/my_story
23 | - stories/my_story.rb
24 |
25 | ==== Complex
26 | You can keep your stories organized by putting stories into sub-directories. To do this with the generator use:
27 |
28 | {{{merb-gen story complex/story_group/story_file}}}
29 |
30 | This will generate the following files:
31 | - steps/complex_story_group_story_file.rb
32 | - stories/complex/story_group/story_file
33 | - stories/complex/story_group/story_file.rb
34 |
35 | === Usage Examples
36 | merb_stories has a rake task for running your stories. To include it you need to make merb_stories a dependency in your app.
37 |
38 | To make the rake file available, in config/init.rb include the following line:
39 | {{{dependency "merb_stories" if Merb.environment == "test"}}}
40 |
41 | Once you have the rake file available you can run the stories:
42 |
43 | rake story[my_story]
44 |
45 | OR for complex examples
46 |
47 | rake story[complex/story_group/story_file]
48 |
49 | OR to run all the stories
50 |
51 | rake story[all]
--------------------------------------------------------------------------------
/merb_builder/spec/builder_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
3 | describe "Builder" do
4 | before(:each) do
5 | @xml = ::Builder::XmlMarkup.new :indent => 2
6 | @xml.instruct!
7 | end
8 |
9 | it "should be able to render Builder templates" do
10 | c = dispatch_to(BuilderController, :index, :format => "xml")
11 | @xml.hello "World"
12 | c.body.should == @xml.target!
13 | end
14 |
15 | it "should be able to render partial Builder templates and use locals" do
16 | c = dispatch_to(PartialBuilder, :index, :format => "xml")
17 | @xml.hello "World"
18 | c.body.should == @xml.target!
19 | end
20 |
21 | it "should be able to have ivars defined in both the controller and the parent template" do
22 | c = dispatch_to(PartialIvars, :index, :format => "xml")
23 | @xml.p "Partial Builder"
24 | c.body.should == @xml.target!
25 | end
26 |
27 | it "should use the builder configuration in Merb::Config" do
28 | c = dispatch_to(BuilderConfig, :index, :format => "xml")
29 | xml = ::Builder::XmlMarkup.new :indent => 4
30 | xml.instruct!
31 | xml.foo do
32 | xml.bar "baz"
33 | end
34 | c.body.should == xml.target!
35 | end
36 |
37 | it "should capture_builder properly" do
38 | c = dispatch_to(CaptureBuilder, :index, :format => "xml")
39 | xml = ::Builder::XmlMarkup.new :indent => 4
40 | xml.instruct!
41 | xml.comment! "I would not say such things if I were you"
42 | xml.node 'Capture'
43 |
44 | c.body.should == xml.target!
45 | end
46 |
47 | it "should concat_builder properly" do
48 | c = dispatch_to(ConcatBuilder, :index, :format => "xml")
49 | xml = ::Builder::XmlMarkup.new :indent => 4
50 | xml.instruct!
51 | xml.node 'Concat'
52 |
53 | c.body.should == xml.target!.chomp
54 | end
55 |
56 | end
57 |
--------------------------------------------------------------------------------
/merb_activerecord/specs/merb_active_record_session_spec.rb:
--------------------------------------------------------------------------------
1 | $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2 | require 'merb-core'
3 | require 'merb-core/test'
4 | require 'merb-core/test/helpers'
5 |
6 | Merb::BootLoader.before_app_loads do
7 | require "merb/session/active_record_session"
8 | end
9 |
10 | Merb.start_environment( :environment => 'test', :adapter => 'runner',
11 | :session_store => 'activerecord')
12 |
13 | Spec::Runner.configure do |config|
14 | config.include Merb::Test::RequestHelper
15 | end
16 |
17 | require 'merb_activerecord'
18 | ActiveRecord::Base.establish_connection(:adapter => "sqlite3",
19 | :dbfile => ":memory:")
20 |
21 | ActiveRecord::Schema.define do
22 | create_table :sessions do |t|
23 | t.column :session_id, :string
24 | t.column :data, :text
25 | t.column :created_at, :datetime
26 | end
27 | end
28 |
29 | # Load up the shared specs from merb-core
30 | if (gem_spec = Gem.source_index.search(Gem::Dependency.new('merb-core', '>=0.9.6')).last) &&
31 | gem_spec.files.include?('spec/public/session/controllers/sessions.rb')
32 | require gem_spec.full_gem_path / 'spec/public/session/controllers/sessions.rb'
33 | require gem_spec.full_gem_path / 'spec/public/session/session_spec.rb'
34 | end
35 |
36 | describe Merb::ActiveRecordSession do
37 |
38 | before do
39 | @session_class = Merb::ActiveRecordSession
40 | @session = @session_class.generate
41 | end
42 |
43 | it_should_behave_like "All session-store backends"
44 |
45 | it "should have a session_store_type class attribute" do
46 | @session.class.session_store_type.should == :activerecord
47 | end
48 |
49 | end
50 |
51 | describe Merb::ActiveRecordSession, "mixed into Merb::Controller" do
52 |
53 | before(:all) { @session_class = Merb::ActiveRecordSession }
54 |
55 | it_should_behave_like "All session-stores mixed into Merb::Controller"
56 |
57 | end
--------------------------------------------------------------------------------
/merb_test_unit/lib/asserts/hpricot_asserts.rb:
--------------------------------------------------------------------------------
1 | # http://yehudakatz.com/2007/01/27/a-better-assert_select-assert_elements/
2 | # based on assert_elements
3 | # Author: Yehuda Katz
4 | # Email: wycats @nospam@ gmail.com
5 | # Web: http://www.yehudakatz.com
6 | #
7 | # which was based on HpricotTestHelper
8 | # Author: Luke Redpath
9 | # Email: contact @nospam@ lukeredpath.co.uk
10 | # Web: www.lukeredpath.co.uk / opensource.agileevolved.com
11 |
12 | module Merb::Test::Unit::HpricotAsserts
13 | include Test::Unit::Assertions
14 | # include Merb::Test::HpricotHelper
15 |
16 | def assert_elements(css_query, output = nil, equality = {}, &block)
17 | message = equality.delete(:message) if equality.is_a?(Hash)
18 |
19 | case equality
20 | when Numeric then equality = {:count => equality}
21 | when Range then equality = {:minimum => equality.to_a.first, :maximum => equality.to_a.last }
22 | else equality ||= {}
23 | end
24 |
25 | equality.merge!({:minimum => 1}) if (equality.keys & [:minimum, :maximum, :count]).empty?
26 |
27 | els = get_elements(css_query, equality[:text], output)
28 |
29 | ret = equality.keys.include?(:minimum) ? (els.size >= equality[:minimum]) : true
30 | ret &&= (els.size <= equality[:maximum]) if equality.keys.include?(:maximum)
31 | ret &&= (els.size == equality[:count]) if equality.keys.include?(:count)
32 |
33 | if block && !els.empty?
34 | ret &&= self.dup.instance_eval do
35 | @output = HpricotTestHelper::DocumentOutput.new(els.inner_html)
36 | @block = true
37 | instance_eval(&block)
38 | end
39 | end
40 |
41 | if(equality[:count] != 0)
42 | assert(ret, "#{ message } \"#{ css_query }\" with \"#{ equality.inspect }\" was not found.")
43 | else
44 | assert(ret, "#{ message } \"#{ css_query }\" with \"#{ equality.reject{|k,v| k == :count}.inspect }\" was found, but you specified :count => 0.")
45 | end
46 | ret
47 | end
48 | end
--------------------------------------------------------------------------------
/merb_activerecord/lib/merb/session/active_record_session.rb:
--------------------------------------------------------------------------------
1 | require 'merb-core/dispatch/session'
2 | require 'active_record'
3 | require 'base64'
4 |
5 | module Merb
6 |
7 | # Sessions stored in ActiveRecord model.
8 | #
9 | # To use ActiveRecord based sessions add the following to config/init.rb:
10 | #
11 | # Merb::Config[:session_store] = 'activerecord'
12 |
13 | class ActiveRecordSessionStore < ::ActiveRecord::Base
14 |
15 | table_name = (Merb::Plugins.config[:merb_active_record][:session_table_name] || "sessions")
16 |
17 | set_table_name table_name
18 |
19 | serialize :data
20 |
21 | class << self
22 |
23 | # ==== Parameters
24 | # session_id:: ID of the session to retrieve.
25 | #
26 | # ==== Returns
27 | # ContainerSession:: The session corresponding to the ID.
28 | def retrieve_session(session_id)
29 | if item = find_by_session_id(session_id)
30 | item.data
31 | end
32 | end
33 |
34 | # ==== Parameters
35 | # session_id:: ID of the session to set.
36 | # data:: The session to set.
37 | def store_session(session_id, data)
38 | if item = find_by_session_id(session_id)
39 | item.update_attributes!(:data => data)
40 | else
41 | create(:session_id => session_id, :data => data)
42 | end
43 | end
44 |
45 | # ==== Parameters
46 | # session_id:: ID of the session to delete.
47 | def delete_session(session_id)
48 | delete_all(["#{connection.quote_column_name('session_id')} IN (?)", session_id])
49 | end
50 |
51 | end
52 |
53 | end
54 |
55 | class ActiveRecordSession < SessionStoreContainer
56 |
57 | # The session store type
58 | self.session_store_type = :activerecord
59 |
60 | # The store object is the model class itself
61 | self.store = ActiveRecordSessionStore
62 |
63 | end
64 |
65 | end
--------------------------------------------------------------------------------
/merb_laszlo/lib/merb-laszlo/controllers.rb:
--------------------------------------------------------------------------------
1 | require "pathname"
2 | module Merb
3 | class Controller
4 |
5 | def laszlo(str)
6 | @lz_resources ||= []
7 |
8 | root, template_location = self.class._template_roots.last
9 | resource_dir = root / send(template_location, "resources")[0...-1]
10 | Merb.logger.info! "Resource dir: #{resource_dir}"
11 |
12 | zip_filename = "#{Laszlo.file_name}.zip"
13 | FileUtils.mkdir_p(Merb.root / "tmp")
14 | Zip::ZipFile.open(Merb.root / "tmp" / zip_filename, Zip::ZipFile::CREATE) do |zipfile|
15 | zipfile.get_output_stream("#{action_name}.lzx") do |f|
16 | f.puts str
17 | end
18 | @lz_resources.each do |resource|
19 | filepath = resource.split("/")
20 | dir = filepath[1...-1].join("/").gsub(/^#{Merb.root}/, "")
21 | filename = filepath[-1]
22 | zipfile.mkdir(dir) unless zipfile.find_entry(dir) || dir.empty?
23 | Merb.logger.info! "Looking for #{resource_dir / resource}"
24 | if File.file?(resource_dir / resource)
25 | zipfile.add(resource, resource_dir / resource)
26 | elsif File.file?(root / resource)
27 | zipfile.add(resource, root / resource)
28 | end
29 | end
30 | end
31 | c = Curl::Easy.new
32 |
33 | c.url = "#{Laszlo.url}/file_upload.jsp"
34 | c.multipart_form_post = true
35 |
36 | file = Curl::PostField.file("myFile", Merb.root / "tmp" / zip_filename, zip_filename)
37 | file.content_type = "application/zip"
38 |
39 | c.http_post(
40 | file,
41 | Curl::PostField.content("uid", "#{Laszlo.app_name}__#{controller_name}"))
42 |
43 | File.delete(Merb.root / "tmp" / zip_filename)
44 |
45 | if c.response_code == 200
46 | redirect("#{Laszlo.url}/my-apps/#{Laszlo.app_name}__#{controller_name}/#{action_name}.lzx")
47 | else
48 | raise NotAcceptable
49 | end
50 | end
51 |
52 | end
53 | end
--------------------------------------------------------------------------------
/merb_activerecord/specs/merb_active_record_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
3 | describe Merb::Orms::ActiveRecord::Connect do
4 | it "is loaded at plugin bootstrap" do
5 | defined?(Merb::Orms::ActiveRecord::Connect).should == "constant"
6 | end
7 |
8 | it "is a merb bootloader" do
9 | Merb::Orms::ActiveRecord::Connect.superclass.should == Merb::BootLoader
10 | end
11 | end
12 |
13 | describe "Merb ActiveRecord extension" do
14 | before :all do
15 | @wd = Dir.pwd
16 | Merb.stub!(:dir_for).with(:config).and_return(@wd)
17 | @config_file_path = @wd / "config" / "database.yml"
18 | @sample_file_path = @wd / "config" / "database.yml.sample"
19 |
20 | @sample_source = Merb::Orms::ActiveRecord.sample_source
21 | @config_sample = Erubis.load_yaml_file(@sample_source)
22 | end
23 |
24 | it "is loaded at plugin booststrap" do
25 | defined?(Merb::Orms::ActiveRecord).should == "constant"
26 | end
27 |
28 | it "loads config from Merb configurations directory" do
29 | Merb::Orms::ActiveRecord.config_file.should == @config_file_path
30 | end
31 |
32 | it "loads config sample from Merb configurations directory" do
33 | Merb::Orms::ActiveRecord.sample_dest.should == @sample_file_path
34 | end
35 |
36 | it "provides a sample database.yml with development environment" do
37 | @config_sample[:development].should be_an_instance_of(Hash)
38 | end
39 |
40 | it "provides a sample database.yml with test environment" do
41 | @config_sample[:test].should be_an_instance_of(Hash)
42 | end
43 |
44 | it "provides a sample database.yml with production environment" do
45 | @config_sample[:production].should be_an_instance_of(Hash)
46 | end
47 |
48 | it "uses Unicode and localhost in sample" do
49 | @config_sample[:development][:host].should == "localhost"
50 | @config_sample[:development][:encoding].should == "utf8"
51 | end
52 |
53 | it "provides Rack with a way to start a transcantion" do
54 | Merb::Orms::ActiveRecord.should respond_to(:open_sandbox!)
55 | end
56 |
57 | it "provides Rack with a way to stop a transcantion" do
58 | Merb::Orms::ActiveRecord.should respond_to(:close_sandbox!)
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/merb_sequel/lib/generators/templates/resource_controller/app/controllers/%file_name%.rb:
--------------------------------------------------------------------------------
1 | <% with_modules(modules) do -%>
2 | class <%= class_name %> < Application
3 | # provides :xml, :yaml, :js
4 |
5 | # GET /<%= resource_path %>
6 | def index
7 | @<%= plural_model %> = <%= model_class_name %>.all
8 | display @<%= plural_model %>
9 | end
10 |
11 | # GET /<%= resource_path %>/:id
12 | def show
13 | @<%= singular_model %> = <%= model_class_name %>[params[:id]]
14 | raise NotFound unless @<%= singular_model %>
15 | display @<%= singular_model %>
16 | end
17 |
18 | # GET /<%= resource_path %>/new
19 | def new
20 | only_provides :html
21 | @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
22 | render
23 | end
24 |
25 | # POST /<%= resource_path %>
26 | def create
27 | @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
28 | if @<%= singular_model %>.save
29 | redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
30 | else
31 | render :new
32 | end
33 | end
34 |
35 | # GET /<%= resource_path %>/:id/edit
36 | def edit
37 | only_provides :html
38 | @<%= singular_model %> = <%= model_class_name %>[params[:id]]
39 | raise NotFound unless @<%= singular_model %>
40 | render
41 | end
42 |
43 | # PUT /<%= resource_path %>/:id
44 | def update
45 | @<%= singular_model %> = <%= model_class_name %>[params[:id]]
46 | raise NotFound unless @<%= singular_model %>
47 | if @<%= singular_model %>.update(params[:<%= singular_model %>])
48 | redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
49 | else
50 | raise BadRequest
51 | end
52 | end
53 |
54 | # DELETE /<%= resource_path %>/:id
55 | def destroy
56 | @<%= singular_model %> = <%= model_class_name %>[params[:id]]
57 | raise NotFound unless @<%= singular_model %>
58 | if @<%= singular_model %>.destroy
59 | redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>s)
60 | else
61 | raise BadRequest
62 | end
63 | end
64 |
65 | end
66 | <% end -%>
--------------------------------------------------------------------------------
/merb_activerecord/lib/generators/templates/resource_controller/app/controllers/%file_name%.rb:
--------------------------------------------------------------------------------
1 | class <%= class_name %> < Application
2 | # provides :xml, :yaml, :js
3 |
4 | # GET /<%= resource_path %>
5 | def index
6 | @<%= plural_model %> = <%= model_class_name %>.find(:all)
7 | display @<%= plural_model %>
8 | end
9 |
10 | # GET /<%= resource_path %>/:id
11 | def show
12 | @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
13 | raise NotFound unless @<%= singular_model %>
14 | display @<%= singular_model %>
15 | end
16 |
17 | # GET /<%= resource_path %>/new
18 | def new
19 | only_provides :html
20 | @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
21 | render
22 | end
23 |
24 | # POST /<%= resource_path %>
25 | def create
26 | @<%= singular_model %> = <%= model_class_name %>.new(params[:<%= singular_model %>])
27 | if @<%= singular_model %>.save
28 | redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
29 | else
30 | render :new
31 | end
32 | end
33 |
34 | # GET /<%= resource_path %>/:id/edit
35 | def edit
36 | only_provides :html
37 | @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
38 | raise NotFound unless @<%= singular_model %>
39 | render
40 | end
41 |
42 | # PUT /<%= resource_path %>/:id
43 | def update
44 | @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
45 | raise NotFound unless @<%= singular_model %>
46 | if @<%= singular_model %>.update_attributes(params[:<%= singular_model %>])
47 | redirect url(:<%= (modules.collect{|m| m.downcase} << singular_model).join("_") %>, @<%= singular_model %>)
48 | else
49 | raise BadRequest
50 | end
51 | end
52 |
53 | # DELETE /<%= resource_path %>/:id
54 | def destroy
55 | @<%= singular_model %> = <%= model_class_name %>.find_by_id(params[:id])
56 | raise NotFound unless @<%= singular_model %>
57 | if @<%= singular_model %>.destroy
58 | redirect url(:<%= (modules.collect{|m| m.downcase} << plural_model).join("_") %>)
59 | else
60 | raise BadRequest
61 | end
62 | end
63 |
64 | end
65 |
--------------------------------------------------------------------------------
/merb_builder/lib/merb_builder/template.rb:
--------------------------------------------------------------------------------
1 | module Merb::Template
2 |
3 | class Builder
4 |
5 | # Defines a method for calling a specific Builder template.
6 | #
7 | # ==== Parameters
8 | # path:: Path to the template file.
9 | # name<~to_s>:: The name of the template method.
10 | # locals:: A list of locals to assign from the args passed into the compiled template.
11 | # mod::
12 | # The class or module wherein this method should be defined.
13 | def self.compile_template(io, name, locals, mod)
14 | path = File.expand_path(io.path)
15 | method = mod.is_a?(Module) ? :module_eval : :instance_eval
16 | assigns = locals.inject([]) do |a, l|
17 | a << "#{l} = _locals[#{l.inspect}];"
18 | end.join
19 | mod.send(method, %{
20 | def #{name}(_locals={})
21 | @_engine = 'builder'
22 |
23 | #{assigns}
24 |
25 | config = (Merb.config[:builder] || {}).inject({}) do |c, (k, v)|
26 | c[k.to_sym] = v
27 | c
28 | end
29 | xml = ::Builder::XmlMarkup.new(config)
30 | self.instance_eval %{#{io.read}}
31 | xml.target!
32 | end
33 | })
34 |
35 | name
36 | end
37 |
38 | module Mixin
39 | def _builder_buffer(the_binding)
40 | @_buffer = eval("xml", the_binding, __FILE__, __LINE__)
41 | end
42 | # ==== Parameters
43 | # *args:: Arguments to pass to the block.
44 | # &block:: The template block to call.
45 | #
46 | # ==== Returns
47 | # String:: The output of the block.
48 | #
49 | # ==== Examples
50 | # Capture being used in a .html.erb page:
51 | #
52 | # @foo = capture do
53 | # xml.instruct!
54 | # xml.foo do
55 | # xml.bar "baz"
56 | # end
57 | # xml.target!
58 | # end
59 | def capture_builder(*args, &block)
60 | block.call(*args)
61 | end
62 |
63 | def concat_builder(string, binding)
64 | _builder_buffer(binding) << string
65 | end
66 |
67 | end
68 | Merb::Template.register_extensions(self, %w[builder])
69 | end
70 | end
71 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/stylesheets/screw.css:
--------------------------------------------------------------------------------
1 | html {
2 | padding: 0.5em;
3 | font-family: Georgia, serif;
4 | background: #EDEBD5;
5 | }
6 |
7 | li {
8 | list-style-type: none;
9 | }
10 |
11 | .focused {
12 | background-color: #F4F2E4;
13 | }
14 |
15 | .focused * {
16 | opacity: 1.0;
17 | }
18 |
19 | h1, h2, p {
20 | opacity: 0.4;
21 | }
22 |
23 | .describes {
24 | padding-left: 0;
25 | }
26 |
27 | .describes h1 {
28 | font-size: 1.1em;
29 | color: #877C21;
30 | line-height: 1.8em;
31 | margin: 0pt 0pt 0.6em;
32 | border-bottom: 1px solid transparent;
33 | }
34 |
35 | .describes h1:hover {
36 | cursor: pointer;
37 | color: #000;
38 | background-color: #F4F2E4;
39 | border-bottom: 1px solid #9A8E51;
40 | }
41 |
42 | .describes .describe {
43 | margin-left: 0.6em;
44 | padding-left: 0.6em;
45 | border: 1px dashed grey;
46 | }
47 |
48 | .describes .describe .its {}
49 |
50 | .describes .describe .its .it {
51 | list-style-type: lower-roman;
52 | list-style-position: outside;
53 | }
54 |
55 | .describes .describe .its .it h2 {
56 | font-weight: normal;
57 | font-style: italic;
58 | padding-left: 0.5em;
59 | font-size: 1.0em;
60 | color: #877C21;
61 | line-height: 1.8em;
62 | margin: 0 0 0.5em;
63 | border-bottom: 1px solid transparent;
64 | }
65 |
66 | .describes .describe .its .it.enqueued h2 {
67 | background-color: #CC6600;
68 | color: white !important;
69 | }
70 |
71 | .describes .describe .its .it.passed h2 {
72 | background-color: #5A753D;
73 | color: white !important;
74 | }
75 |
76 | .describes .describe .its .it.failed h2 {
77 | background-color: #993300;
78 | color: white !important;
79 | }
80 |
81 | .describes .describe .its .it.failed p {
82 | margin-left: 1em;
83 | color: #993300;
84 | }
85 |
86 | .describes .describe .its .it h2:hover {
87 | cursor: pointer;
88 | color: #000 !important;
89 | border-bottom: 1px solid #9A8E51;
90 | }
--------------------------------------------------------------------------------
/merb_jquery/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "extlib"
4 | require 'merb-core/tasks/merb_rake_helper'
5 | require "spec/rake/spectask"
6 |
7 | ##############################################################################
8 | # Package && release
9 | ##############################################################################
10 | RUBY_FORGE_PROJECT = "merb"
11 | PROJECT_URL = "http://merbivore.com"
12 | PROJECT_SUMMARY = "Merb plugin that provides jQuery support"
13 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
14 |
15 | GEM_AUTHOR = "Michael D. Ivey"
16 | GEM_EMAIL = "ivey@gweezlebur.com"
17 |
18 | GEM_NAME = "merb_jquery"
19 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
21 |
22 | RELEASE_NAME = "REL #{GEM_VERSION}"
23 |
24 | require "extlib/tasks/release"
25 |
26 | spec = Gem::Specification.new do |s|
27 | s.rubyforge_project = RUBY_FORGE_PROJECT
28 | s.name = GEM_NAME
29 | s.version = GEM_VERSION
30 | s.platform = Gem::Platform::RUBY
31 | s.has_rdoc = true
32 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
33 | s.summary = PROJECT_SUMMARY
34 | s.description = PROJECT_DESCRIPTION
35 | s.author = GEM_AUTHOR
36 | s.email = GEM_EMAIL
37 | s.homepage = PROJECT_URL
38 | s.add_dependency('merb-core', '>= 0.9.9')
39 | s.require_path = 'lib'
40 | s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib}/**/*")
41 | end
42 |
43 | Rake::GemPackageTask.new(spec) do |pkg|
44 | pkg.gem_spec = spec
45 | end
46 |
47 | desc "Install the gem"
48 | task :install do
49 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
50 | end
51 |
52 | desc "Uninstall the gem"
53 | task :uninstall do
54 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
55 | end
56 |
57 | desc "Create a gemspec file"
58 | task :gemspec do
59 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
60 | file.puts spec.to_ruby
61 | end
62 | end
63 |
64 | desc "Run all examples (or a specific spec with TASK=xxxx)"
65 | Spec::Rake::SpecTask.new('spec') do |t|
66 | t.spec_opts = ["-cfs"]
67 | t.spec_files = begin
68 | if ENV["TASK"]
69 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
70 | else
71 | FileList['spec/**/*_spec.rb']
72 | end
73 | end
74 | end
75 |
76 | desc 'Default: run spec examples'
77 | task :default => 'spec'
--------------------------------------------------------------------------------
/merb_parts/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "extlib"
4 | require 'merb-core/tasks/merb_rake_helper'
5 | require "spec/rake/spectask"
6 |
7 | ##############################################################################
8 | # Package && release
9 | ##############################################################################
10 | RUBY_FORGE_PROJECT = "merb"
11 | PROJECT_URL = "http://merbivore.com"
12 | PROJECT_SUMMARY = "Merb plugin that provides Part Controllers."
13 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
14 |
15 | GEM_AUTHOR = "Daniel Neighman"
16 | GEM_EMAIL = "has.sox@gmail.com"
17 |
18 | GEM_NAME = "merb_parts"
19 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
21 |
22 | RELEASE_NAME = "REL #{GEM_VERSION}"
23 |
24 | require "extlib/tasks/release"
25 |
26 | spec = Gem::Specification.new do |s|
27 | s.rubyforge_project = RUBY_FORGE_PROJECT
28 | s.name = GEM_NAME
29 | s.version = GEM_VERSION
30 | s.platform = Gem::Platform::RUBY
31 | s.has_rdoc = true
32 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
33 | s.summary = PROJECT_SUMMARY
34 | s.description = PROJECT_DESCRIPTION
35 | s.author = GEM_AUTHOR
36 | s.email = GEM_EMAIL
37 | s.homepage = PROJECT_URL
38 | s.add_dependency('merb-core', '>= 0.9.9')
39 | s.require_path = 'lib'
40 | s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib}/**/*")
41 | end
42 |
43 | Rake::GemPackageTask.new(spec) do |pkg|
44 | pkg.gem_spec = spec
45 | end
46 |
47 | desc "Install the gem"
48 | task :install do
49 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
50 | end
51 |
52 | desc "Uninstall the gem"
53 | task :uninstall do
54 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
55 | end
56 |
57 | desc "Create a gemspec file"
58 | task :gemspec do
59 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
60 | file.puts spec.to_ruby
61 | end
62 | end
63 |
64 | desc "Run all examples (or a specific spec with TASK=xxxx)"
65 | Spec::Rake::SpecTask.new('spec') do |t|
66 | t.spec_opts = ["-cfs"]
67 | t.spec_files = begin
68 | if ENV["TASK"]
69 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
70 | else
71 | FileList['spec/**/*_spec.rb']
72 | end
73 | end
74 | end
75 |
76 | desc 'Default: run spec examples'
77 | task :default => 'spec'
78 |
--------------------------------------------------------------------------------
/merb_activerecord/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "extlib"
4 | require 'merb-core/tasks/merb_rake_helper'
5 | require "spec/rake/spectask"
6 |
7 | ##############################################################################
8 | # Package && release
9 | ##############################################################################
10 | RUBY_FORGE_PROJECT = "merb"
11 | PROJECT_URL = "http://merbivore.com"
12 | PROJECT_SUMMARY = "Merb plugin that provides ActiveRecord support for Merb"
13 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
14 |
15 | GEM_AUTHOR = "Duane Johnson"
16 | GEM_EMAIL = "canadaduane@gmail.com"
17 |
18 | GEM_NAME = "merb_activerecord"
19 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20 | GEM_VERSION = ("1.0.0.1") + PKG_BUILD
21 |
22 | RELEASE_NAME = "REL #{GEM_VERSION}"
23 |
24 | require "extlib/tasks/release"
25 |
26 | spec = Gem::Specification.new do |s|
27 | s.rubyforge_project = RUBY_FORGE_PROJECT
28 | s.name = GEM_NAME
29 | s.version = GEM_VERSION
30 | s.platform = Gem::Platform::RUBY
31 | s.has_rdoc = true
32 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
33 | s.summary = PROJECT_SUMMARY
34 | s.description = PROJECT_DESCRIPTION
35 | s.author = GEM_AUTHOR
36 | s.email = GEM_EMAIL
37 | s.homepage = PROJECT_URL
38 | s.add_dependency('merb-core', '>= 0.9.9')
39 | s.require_path = 'lib'
40 | s.files = %w(LICENSE README Rakefile TODO Generators) + Dir.glob("{lib}/**/*")
41 | end
42 |
43 | Rake::GemPackageTask.new(spec) do |pkg|
44 | pkg.gem_spec = spec
45 | end
46 |
47 | desc "Install the gem"
48 | task :install do
49 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
50 | end
51 |
52 | desc "Uninstall the gem"
53 | task :uninstall do
54 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
55 | end
56 |
57 | desc "Create a gemspec file"
58 | task :gemspec do
59 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
60 | file.puts spec.to_ruby
61 | end
62 | end
63 |
64 | desc "Run all examples (or a specific spec with TASK=xxxx)"
65 | Spec::Rake::SpecTask.new('spec') do |t|
66 | t.spec_opts = ["-cfs"]
67 | t.spec_files = begin
68 | if ENV["TASK"]
69 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
70 | else
71 | FileList['spec/**/*_spec.rb']
72 | end
73 | end
74 | end
75 |
76 | desc 'Default: run spec examples'
77 | task :default => 'spec'
78 |
--------------------------------------------------------------------------------
/merb_laszlo/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rubygems/specification'
3 | require 'date'
4 | require 'rake/gempackagetask'
5 | require "extlib"
6 | require 'merb-core/tasks/merb_rake_helper'
7 | require "spec/rake/spectask"
8 |
9 | ##############################################################################
10 | # Package && release
11 | ##############################################################################
12 | RUBY_FORGE_PROJECT = "merb"
13 | PROJECT_URL = "http://merbivore.com"
14 | PROJECT_SUMMARY = "Merb plugin that provides support for Laszlo."
15 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
16 |
17 | GEM_AUTHOR = "Yehuda Katz"
18 | GEM_EMAIL = "ykatz@engineyard.com"
19 |
20 | GEM_NAME = "merb_laszlo"
21 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
22 | GEM_VERSION = "0.9.9" + PKG_BUILD
23 |
24 | RELEASE_NAME = "REL #{GEM_VERSION}"
25 |
26 | require "extlib/tasks/release"
27 |
28 | spec = Gem::Specification.new do |s|
29 | s.rubyforge_project = RUBY_FORGE_PROJECT
30 | s.name = GEM_NAME
31 | s.version = GEM_VERSION
32 | s.platform = Gem::Platform::RUBY
33 | s.has_rdoc = true
34 | s.extra_rdoc_files = ["README", "LICENSE"]
35 | s.summary = PROJECT_SUMMARY
36 | s.description = PROJECT_DESCRIPTION
37 | s.author = GEM_AUTHOR
38 | s.email = GEM_EMAIL
39 | s.homepage = PROJECT_URL
40 | s.add_dependency('merb-core', '>= 0.9.9')
41 | s.require_path = 'lib'
42 | s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib}/**/*")
43 | end
44 |
45 | Rake::GemPackageTask.new(spec) do |pkg|
46 | pkg.gem_spec = spec
47 | end
48 |
49 | desc "Install the gem"
50 | task :install do
51 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
52 | end
53 |
54 | desc "Uninstall the gem"
55 | task :uninstall do
56 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
57 | end
58 |
59 | desc "Create a gemspec file"
60 | task :gemspec do
61 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
62 | file.puts spec.to_ruby
63 | end
64 | end
65 |
66 | desc "Run all examples (or a specific spec with TASK=xxxx)"
67 | Spec::Rake::SpecTask.new('spec') do |t|
68 | t.spec_opts = ["-cfs"]
69 | t.spec_files = begin
70 | if ENV["TASK"]
71 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
72 | else
73 | FileList['spec/**/*_spec.rb']
74 | end
75 | end
76 | end
77 |
78 | desc 'Default: run spec examples'
79 | task :default => 'spec'
--------------------------------------------------------------------------------
/merb_stories/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "rake/rdoctask"
4 | require "extlib"
5 | require 'merb-core/tasks/merb_rake_helper'
6 | require "spec/rake/spectask"
7 |
8 | ##############################################################################
9 | # Package && release
10 | ##############################################################################
11 | RUBY_FORGE_PROJECT = "merb"
12 | PROJECT_URL = "http://merbivore.com"
13 | PROJECT_SUMMARY = "Merb plugin that provides RSpec stories support"
14 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
15 |
16 | GEM_AUTHOR = "Yehuda Katz"
17 | GEM_EMAIL = "ykatz@engineyard.com"
18 |
19 | GEM_NAME = "merb_stories"
20 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
21 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
22 |
23 | RELEASE_NAME = "REL #{GEM_VERSION}"
24 |
25 | require "extlib/tasks/release"
26 |
27 | spec = Gem::Specification.new do |s|
28 | s.rubyforge_project = RUBY_FORGE_PROJECT
29 | s.name = GEM_NAME
30 | s.version = GEM_VERSION
31 | s.platform = Gem::Platform::RUBY
32 | s.has_rdoc = true
33 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
34 | s.summary = PROJECT_SUMMARY
35 | s.description = PROJECT_DESCRIPTION
36 | s.author = GEM_AUTHOR
37 | s.email = GEM_EMAIL
38 | s.homepage = PROJECT_URL
39 | s.add_dependency('rspec', '>= 1.1.3')
40 | s.require_path = 'lib'
41 | s.files = %w(LICENSE README Rakefile Generators TODO) + Dir.glob("{lib}/**/*")
42 | end
43 |
44 | Rake::GemPackageTask.new(spec) do |pkg|
45 | pkg.gem_spec = spec
46 | end
47 |
48 | desc "Install the gem"
49 | task :install do
50 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
51 | end
52 |
53 | desc "Uninstall the gem"
54 | task :uninstall do
55 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
56 | end
57 |
58 | desc "Create a gemspec file"
59 | task :gemspec do
60 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
61 | file.puts spec.to_ruby
62 | end
63 | end
64 |
65 | desc "Run all examples (or a specific spec with TASK=xxxx)"
66 | Spec::Rake::SpecTask.new('spec') do |t|
67 | t.spec_opts = ["-cfs"]
68 | t.spec_files = begin
69 | if ENV["TASK"]
70 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
71 | else
72 | FileList['spec/**/*_spec.rb']
73 | end
74 | end
75 | end
76 |
77 | desc 'Default: run spec examples'
78 | task :default => 'spec'
--------------------------------------------------------------------------------
/merb_builder/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "extlib"
4 | require 'merb-core/tasks/merb_rake_helper'
5 | require "spec/rake/spectask"
6 |
7 | ##############################################################################
8 | # Package && release
9 | ##############################################################################
10 | RUBY_FORGE_PROJECT = "merb"
11 | PROJECT_URL = "http://merbivore.com"
12 | PROJECT_SUMMARY = "Merb plugin that provides Builder support"
13 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
14 |
15 | GEM_AUTHOR = "Jonathan Younger"
16 | GEM_EMAIL = "jonathan@daikini.com"
17 |
18 | GEM_NAME = "merb_builder"
19 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
21 |
22 | RELEASE_NAME = "REL #{GEM_VERSION}"
23 |
24 | require "extlib/tasks/release"
25 |
26 | spec = Gem::Specification.new do |s|
27 | s.rubyforge_project = RUBY_FORGE_PROJECT
28 | s.name = GEM_NAME
29 | s.version = GEM_VERSION
30 | s.platform = Gem::Platform::RUBY
31 | s.has_rdoc = true
32 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
33 | s.summary = PROJECT_SUMMARY
34 | s.description = PROJECT_DESCRIPTION
35 | s.author = GEM_AUTHOR
36 | s.email = GEM_EMAIL
37 | s.homepage = PROJECT_URL
38 | s.add_dependency('merb-core', '>= 0.9.9')
39 | s.add_dependency('builder', '>= 2.0.0')
40 | s.require_path = 'lib'
41 | s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib}/**/*")
42 | end
43 |
44 | Rake::GemPackageTask.new(spec) do |pkg|
45 | pkg.gem_spec = spec
46 | end
47 |
48 | desc "Install the gem"
49 | task :install do
50 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
51 | end
52 |
53 | desc "Uninstall the gem"
54 | task :uninstall do
55 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
56 | end
57 |
58 | desc "Create a gemspec file"
59 | task :gemspec do
60 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
61 | file.puts spec.to_ruby
62 | end
63 | end
64 |
65 | desc "Run all examples (or a specific spec with TASK=xxxx)"
66 | Spec::Rake::SpecTask.new('spec') do |t|
67 | t.spec_opts = ["-cfs"]
68 | t.spec_files = begin
69 | if ENV["TASK"]
70 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
71 | else
72 | FileList['spec/**/*_spec.rb']
73 | end
74 | end
75 | end
76 |
77 | desc 'Default: run spec examples'
78 | task :default => 'spec'
79 |
--------------------------------------------------------------------------------
/merb_test_unit/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rubygems/specification'
3 | require 'rake/gempackagetask'
4 | require "extlib"
5 | require 'merb-core/tasks/merb_rake_helper'
6 | require "spec/rake/spectask"
7 |
8 | ##############################################################################
9 | # Package && release
10 | ##############################################################################
11 | RUBY_FORGE_PROJECT = "merb"
12 | PROJECT_URL = "http://merbivore.com"
13 | PROJECT_SUMMARY = "Merb plugin that provides Test::Unit support"
14 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
15 |
16 | GEM_AUTHOR = "Yehuda Katz"
17 | GEM_EMAIL = "ykatz@engineyard.com"
18 |
19 | GEM_NAME = "merb_test_unit"
20 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
21 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
22 |
23 | RELEASE_NAME = "REL #{GEM_VERSION}"
24 |
25 | require "extlib/tasks/release"
26 |
27 | spec = Gem::Specification.new do |s|
28 | s.rubyforge_project = RUBY_FORGE_PROJECT
29 | s.name = GEM_NAME
30 | s.version = GEM_VERSION
31 | s.platform = Gem::Platform::RUBY
32 | s.has_rdoc = true
33 | s.extra_rdoc_files = ["README", "LICENSE"]
34 | s.summary = PROJECT_SUMMARY
35 | s.description = PROJECT_DESCRIPTION
36 | s.author = GEM_AUTHOR
37 | s.email = GEM_EMAIL
38 | s.homepage = PROJECT_URL
39 | s.add_dependency('merb-core', '>= 0.9.9')
40 | s.require_path = 'lib'
41 | s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,test_unit_generators}/**/*")
42 | end
43 |
44 | Rake::GemPackageTask.new(spec) do |pkg|
45 | pkg.gem_spec = spec
46 | end
47 |
48 | desc "Install the gem"
49 | task :install do
50 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
51 | end
52 |
53 | desc "Uninstall the gem"
54 | task :uninstall do
55 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
56 | end
57 |
58 | desc "Create a gemspec file"
59 | task :gemspec do
60 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
61 | file.puts spec.to_ruby
62 | end
63 | end
64 |
65 | desc "Run all examples (or a specific spec with TASK=xxxx)"
66 | Spec::Rake::SpecTask.new('spec') do |t|
67 | t.spec_opts = ["-cfs"]
68 | t.spec_files = begin
69 | if ENV["TASK"]
70 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
71 | else
72 | FileList['spec/**/*_spec.rb']
73 | end
74 | end
75 | end
76 |
77 | desc 'Default: run spec examples'
78 | task :default => 'spec'
79 |
--------------------------------------------------------------------------------
/merb_laszlo/lib/merb-laszlo/helpers.rb:
--------------------------------------------------------------------------------
1 | module Merb
2 | module GlobalHelpers
3 |
4 | def lz(name, *args, &blk)
5 | send("lz_#{name}", *args, &blk)
6 | end
7 |
8 | def lz_reload_button
9 | contents = "Reload" +
10 | tag(:handler, %{LzBrowser.loadJS("window.location = \\\"#{request.full_uri}\\\"")}, :name => "onclick") +
11 | tag(:handler, %{this.bringToFront()}, :name => "oninit")
12 |
13 | tag(:button, contents, :valign => "bottom", :align => "right")
14 | end
15 |
16 | def lz_class(name, extends = nil, opts = {}, &blk)
17 | opts.merge!(:name => name)
18 | opts.merge!(:extends => extends) if extends
19 | tag(:class, nil, opts, &blk)
20 | end
21 |
22 | def lz_text(text, opts = {})
23 | self_closing_tag(:text, {:text => text}.merge(opts))
24 | end
25 |
26 | def lz_window(width = nil, height = nil, opts = {}, &blk)
27 | mrg = {:resizable => true}
28 | mrg.merge!(:width => width) if width
29 | mrg.merge!(:height => height) if height
30 | opts = mrg.merge(opts)
31 | tag(:window, nil, opts, &blk)
32 | end
33 |
34 | def add_lz_resource(src)
35 | @lz_resources ||= []
36 | @lz_resources << src unless URI.parse(src).scheme
37 | end
38 |
39 | def lz_resource(name, src, opts = {})
40 | add_lz_resource(src)
41 | opts.merge!(:name => name, :src => src)
42 | self_closing_tag(:resource, opts)
43 | end
44 |
45 | def lz_on(name, options = {}, *args, &blk)
46 | options.merge!(:name => "on#{name}")
47 | options.merge!(:args => args.map {|x| x.to_s}.join(", ")) unless args.empty?
48 | tag(:handler, capture(&blk), options)
49 | end
50 |
51 | def lz_attr(name, value, type = nil)
52 | mrg = {:name => name, :value => value}
53 | mrg.merge!(:type => type) if type
54 | self_closing_tag(:attribute, mrg)
55 | end
56 |
57 | def lz_def(name, *args, &blk)
58 | tag(:method, blk ? capture(&blk) : "", :name => name, :args => args.map {|x| x.to_s}.join(","))
59 | end
60 |
61 | def lz_view(width, height, bgcolor, options = {}, &blk)
62 | tag(:view, blk ? capture(&blk) : "", {:width => width, :height => height, :bgcolor => bgcolor}.merge(options))
63 | end
64 |
65 | def lz_resource_view(src, options = {}, &blk)
66 | add_lz_resource(src)
67 | tag(:view, blk ? capture(&blk) : "", {:resource => src}.merge(options))
68 | end
69 |
70 | end
71 | end
--------------------------------------------------------------------------------
/merb_screw_unit/spec/controllers/main_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/../spec_helper'
2 |
3 | describe "MerbScrewUnit::Main (controller)" do
4 |
5 | # Feel free to remove the specs below
6 |
7 | before :all do
8 | Merb::Router.prepare { |r| r.add_slice(:MerbScrewUnit) } if standalone?
9 | end
10 |
11 | after :all do
12 | Merb::Router.reset! if standalone?
13 | end
14 |
15 | it "should have access to the slice module" do
16 | controller = dispatch_to(MerbScrewUnit::Main, :index)
17 | controller.slice.should == MerbScrewUnit
18 | controller.slice.should == MerbScrewUnit::Main.slice
19 | end
20 |
21 | it "should have an index action" do
22 | controller = dispatch_to(MerbScrewUnit::Main, :index)
23 | controller.status.should == 200
24 | controller.body.should contain('MerbScrewUnit')
25 | end
26 |
27 | it "should work with the default route" do
28 | controller = get("/merb_screw_unit/main/index")
29 | controller.should be_kind_of(MerbScrewUnit::Main)
30 | controller.action_name.should == 'index'
31 | end
32 |
33 | it "should work with the example named route" do
34 | controller = get("/merb_screw_unit/index.html")
35 | controller.should be_kind_of(MerbScrewUnit::Main)
36 | controller.action_name.should == 'index'
37 | end
38 |
39 | it "should have routes in MerbScrewUnit.routes" do
40 | MerbScrewUnit.routes.should_not be_empty
41 | end
42 |
43 | it "should have a slice_url helper method for slice-specific routes" do
44 | controller = dispatch_to(MerbScrewUnit::Main, 'index')
45 | controller.slice_url(:action => 'show', :format => 'html').should == "/merb_screw_unit/main/show.html"
46 | controller.slice_url(:merb_screw_unit_index, :format => 'html').should == "/merb_screw_unit/index.html"
47 | end
48 |
49 | it "should have helper methods for dealing with public paths" do
50 | controller = dispatch_to(MerbScrewUnit::Main, :index)
51 | controller.public_path_for(:image).should == "/slices/merb_screw_unit/images"
52 | controller.public_path_for(:javascript).should == "/slices/merb_screw_unit/javascripts"
53 | controller.public_path_for(:stylesheet).should == "/slices/merb_screw_unit/stylesheets"
54 | end
55 |
56 | it "should have a slice-specific _template_root" do
57 | MerbScrewUnit::Main._template_root.should == MerbScrewUnit.dir_for(:view)
58 | MerbScrewUnit::Main._template_root.should == MerbScrewUnit::Application._template_root
59 | end
60 |
61 | end
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | ## THESE ARE CRUCIAL
2 | module Merb
3 | # Set this to the version of merb-core that you are building against/for
4 | VERSION = "0.9.9"
5 |
6 | # Set this to the version of merb-more you plan to release
7 | MORE_VERSION = "0.9.9"
8 | end
9 |
10 | GEM_VERSION = Merb::VERSION
11 |
12 | require 'rubygems'
13 | require "rake/clean"
14 | require "rake/gempackagetask"
15 | require 'merb-core/tasks/merb_rake_helper'
16 | require 'fileutils'
17 | include FileUtils
18 |
19 |
20 | gems = %w[
21 | merb_activerecord
22 | merb_sequel
23 | merb_test_unit
24 | merb_stories
25 | merb_screw_unit
26 | merb_jquery
27 | merb_builder
28 | merb_parts
29 | ]
30 |
31 | # Implement standard Rake::GemPackageTask tasks - see merb.thor
32 | task :clobber_package do; FileUtils.rm_rf('pkg'); end
33 | task :package do; end
34 |
35 | desc "Install all gems"
36 | task :install => :install_gems
37 |
38 | desc "Uninstall all gems"
39 | task :uninstall => :uninstall_gems
40 |
41 | desc "Build the merb-more gems"
42 | task :build_gems do
43 | gems.each do |dir|
44 | Dir.chdir(dir) { sh "#{Gem.ruby} -S rake package" }
45 | end
46 | end
47 |
48 | desc "Install the merb-plugins sub-gems"
49 | task :install_gems do
50 | gems.each do |dir|
51 | Dir.chdir(dir) { sh "#{Gem.ruby} -S rake install" }
52 | end
53 | end
54 |
55 | desc "Uninstall the merb-plugins sub-gems"
56 | task :uninstall_gems do
57 | gems.each do |dir|
58 | Dir.chdir(dir) { sh "#{Gem.ruby} -S rake uninstall" }
59 | end
60 | end
61 |
62 | desc "Clobber the merb-plugins sub-gems"
63 | task :clobber_gems do
64 | gems.each do |dir|
65 | Dir.chdir(dir) { sh "#{Gem.ruby} -S rake clobber" }
66 | end
67 | end
68 |
69 | desc "Bundle up all the merb-plugins gems"
70 | task :bundle do
71 | mkdir_p "bundle"
72 | gems.each do |gem|
73 | File.open("#{gem}/Rakefile") do |rakefile|
74 | rakefile.read.detect {|l| l =~ /^GEM_VERSION\s*=\s*"(.*)"$/ }
75 | Dir.chdir(gem){ sh "rake package" }
76 | sh %{cp #{gem}/pkg/#{gem}-#{$1}.gem bundle/}
77 | end
78 | end
79 | end
80 |
81 | desc "Release gems in merb-plugins"
82 | task :release do
83 | gems.each do |dir|
84 | Dir.chdir(dir){ sh "#{Gem.ruby} -S rake release" }
85 | end
86 | end
87 |
88 | desc "Run spec examples for Merb More gems, one by one."
89 | task :spec do
90 | gems.each do |gem|
91 | Dir.chdir(gem) { sh "#{Gem.ruby} -S rake spec" }
92 | end
93 | end
94 |
95 | desc 'Default: run spec examples for all the gems.'
96 | task :default => 'spec'
97 |
--------------------------------------------------------------------------------
/merb_screw_unit/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rubygems/specification'
3 | require 'rake/gempackagetask'
4 | require "extlib"
5 | require 'merb-core/tasks/merb_rake_helper'
6 | require "spec/rake/spectask"
7 |
8 | ##############################################################################
9 | # Package && release
10 | ##############################################################################
11 | RUBY_FORGE_PROJECT = "merb"
12 | PROJECT_URL = "http://merbivore.com"
13 | PROJECT_SUMMARY = "Merb Slice that provides support for Screw.Unit testing"
14 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
15 |
16 | GEM_AUTHOR = "Yehuda Katz"
17 | GEM_EMAIL = "ykatz@engineyard.com"
18 |
19 | GEM_NAME = "merb_screw_unit"
20 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
21 | GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.9") + PKG_BUILD
22 |
23 | RELEASE_NAME = "REL #{GEM_VERSION}"
24 |
25 | require "extlib/tasks/release"
26 |
27 | spec = Gem::Specification.new do |s|
28 | s.rubyforge_project = RUBY_FORGE_PROJECT
29 | s.name = GEM_NAME
30 | s.version = GEM_VERSION
31 | s.platform = Gem::Platform::RUBY
32 | s.has_rdoc = true
33 | s.extra_rdoc_files = ["README", "LICENSE"]
34 | s.summary = PROJECT_SUMMARY
35 | s.description = PROJECT_DESCRIPTION
36 | s.author = GEM_AUTHOR
37 | s.email = GEM_EMAIL
38 | s.homepage = PROJECT_URL
39 | s.add_dependency('merb-core', '>= 0.9.9')
40 | s.add_dependency('merb-slices', '>= 0.9.9')
41 | s.require_path = 'lib'
42 | s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,app,public,stubs}/**/*")
43 | end
44 |
45 | Rake::GemPackageTask.new(spec) do |pkg|
46 | pkg.gem_spec = spec
47 | end
48 |
49 | desc "Install the gem"
50 | task :install do
51 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
52 | end
53 |
54 | desc "Uninstall the gem"
55 | task :uninstall do
56 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
57 | end
58 |
59 | desc "Create a gemspec file"
60 | task :gemspec do
61 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
62 | file.puts spec.to_ruby
63 | end
64 | end
65 |
66 | desc "Run all examples (or a specific spec with TASK=xxxx)"
67 | Spec::Rake::SpecTask.new('spec') do |t|
68 | t.spec_opts = ["-cfs"]
69 | t.spec_files = begin
70 | if ENV["TASK"]
71 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
72 | else
73 | FileList['spec/**/*_spec.rb']
74 | end
75 | end
76 | end
77 |
78 | desc 'Default: run spec examples'
79 | task :default => 'spec'
--------------------------------------------------------------------------------
/merb_sequel/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake/gempackagetask'
3 | require "rake/rdoctask"
4 | require "extlib"
5 | require 'merb-core/tasks/merb_rake_helper'
6 | require "spec/rake/spectask"
7 |
8 | ##############################################################################
9 | # Package && release
10 | ##############################################################################
11 | RUBY_FORGE_PROJECT = "merb"
12 | PROJECT_URL = "http://merbivore.com"
13 | PROJECT_SUMMARY = "Merb plugin that provides support for Sequel and Sequel::Model"
14 | PROJECT_DESCRIPTION = PROJECT_SUMMARY
15 |
16 | GEM_AUTHOR = "Wayne E. Seguin, Lance Carlson, Lori Holden"
17 | GEM_EMAIL = "wayneeseguin@gmail.com, lancecarlson@gmail.com, email@loriholden.com"
18 |
19 | GEM_NAME = "merb_sequel"
20 | PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
21 | GEM_VERSION = (Merb::MORE_VERSION rescue "1.0.0") + PKG_BUILD
22 |
23 | RELEASE_NAME = "REL #{GEM_VERSION}"
24 |
25 | require "extlib/tasks/release"
26 |
27 | spec = Gem::Specification.new do |s|
28 | s.rubyforge_project = RUBY_FORGE_PROJECT
29 | s.name = GEM_NAME
30 | s.version = GEM_VERSION
31 | s.platform = Gem::Platform::RUBY
32 | s.has_rdoc = true
33 | s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
34 | s.summary = PROJECT_SUMMARY
35 | s.description = PROJECT_DESCRIPTION
36 | s.author = GEM_AUTHOR
37 | s.email = GEM_EMAIL
38 | s.homepage = PROJECT_URL
39 | s.add_dependency("merb-core", ">= 0.9.9")
40 | s.add_dependency("sequel", ">= 1.4.0")
41 | s.files = %w(LICENSE README Rakefile TODO Generators) + Dir.glob("{lib}/**/*")
42 | end
43 |
44 | Rake::GemPackageTask.new(spec) do |pkg|
45 | pkg.gem_spec = spec
46 | end
47 |
48 | desc "Install the gem"
49 | task :install do
50 | Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
51 | end
52 |
53 | desc "Uninstall the gem"
54 | task :uninstall do
55 | Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
56 | end
57 |
58 | desc "Create a gemspec file"
59 | task :gemspec do
60 | File.open("#{GEM_NAME}.gemspec", "w") do |file|
61 | file.puts spec.to_ruby
62 | end
63 | end
64 |
65 | desc "Run all examples (or a specific spec with TASK=xxxx)"
66 | Spec::Rake::SpecTask.new('spec') do |t|
67 | t.spec_opts = ["-cfs"]
68 | t.spec_files = begin
69 | if ENV["TASK"]
70 | ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
71 | else
72 | FileList['spec/**/*_spec.rb']
73 | end
74 | end
75 | end
76 |
77 | desc 'Default: run spec examples'
78 | task :default => 'spec'
79 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/screw.mock.js:
--------------------------------------------------------------------------------
1 | Screw.Mock = {
2 | confirmWith: function(val) {
3 | Screw.Mock.confirmText = null;
4 | iframeWindow.confirm = function(str) {
5 | Screw.Mock.confirmText = str;
6 | return val;
7 | };
8 | }
9 | };
10 | Screw.XHR = function() {};
11 | Screw.XHR.returns = function(str, type, status) {
12 | codes = {
13 | 100: "Continue",
14 | 101: "Switching Protocols",
15 | 200: "OK",
16 | 201: "Created",
17 | 202: "Accepted",
18 | 203: "Non-Authoritative Information",
19 | 204: "No Content",
20 | 205: "Reset Content",
21 | 206: "Partial Content",
22 | 300: "Multiple Choices",
23 | 301: "Moved Permanently",
24 | 302: "Found",
25 | 303: "See Other",
26 | 304: "Not Modified",
27 | 305: "Use Proxy",
28 | 307: "Temporary Redirect",
29 | 400: "Bad Request",
30 | 401: "Unauthorized",
31 | 402: "Payment Required",
32 | 403: "Forbidden",
33 | 404: "Not Found",
34 | 405: "Method Not Allowed",
35 | 406: "Not Acceptable",
36 | 407: "Proxy Authentication Required",
37 | 408: "Request Timeout",
38 | 409: "Conflict",
39 | 410: "Gone",
40 | 411: "Length Required",
41 | 412: "Precondition Failed",
42 | 413: "Request Entity Too Large",
43 | 414: "Request-URI Too Long",
44 | 415: "Unsupported Media Type",
45 | 416: "Requested Range Not Satisfiable",
46 | 417: "Expectation Failed",
47 | 422: "Unprocessable Entity",
48 | 500: "Internal Server Error",
49 | 501: "Not Implemented",
50 | 502: "Bad Gateway",
51 | 503: "Service Unavailable",
52 | 504: "Gateway Timeout",
53 | 505: "HTTP Version Not Supported"
54 | } ;
55 | Screw.XHR.prototype.responseText = str;
56 | Screw.XHR.prototype.status = status || 200;
57 | Screw.XHR.prototype.statusText = codes[status || 200];
58 | Screw.XHR.prototype.headers = Screw.XHR.prototype.headers || {};
59 | Screw.XHR.prototype.headers["content-type"] = type;
60 | if(type == "xml") Screw.XHR.prototype.responseXML = $(str).get();
61 | };
62 | Screw.XHR.headers = function(headers) {
63 | Screw.XHR.prototype.headers = headers;
64 | };
65 | Screw.XHR.prototype = {
66 | abort: function() {},
67 | getAllResponseHeaders: function() {},
68 | getResponseHeader: function(header) {
69 | return this.headers[header.toLowerCase()];
70 | },
71 | open: function(method, url, async, user, pass) {
72 | Screw.XHR.url = url;
73 | },
74 | send: function(content) {
75 | this.readyState = 4;
76 | },
77 | setRequestHeader: function(label, value) {}
78 | };
--------------------------------------------------------------------------------
/merb_screw_unit/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module Merb
2 | module MerbScrewUnit
3 | module ApplicationHelper
4 |
5 | # @param *segments Path segments to append.
6 | #
7 | # @return
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 Path segments to append.
14 | #
15 | # @return
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 | def js_include_tag(*files)
22 | files.map do |file|
23 | super(javascript_path(file))
24 | end.join
25 | end
26 |
27 | # @param *segments Path segments to append.
28 | #
29 | # @return
30 | # A path relative to the public directory, with added segments.
31 | def stylesheet_path(*segments)
32 | public_path_for(:stylesheet, *segments)
33 | end
34 |
35 | def css_include_tag(*files)
36 | files.map do |file|
37 | super(stylesheet_path(file))
38 | end.join
39 | end
40 |
41 | # Construct a path relative to the public directory
42 | #
43 | # @param The type of component.
44 | # @param *segments Path segments to append.
45 | #
46 | # @return
47 | # A path relative to the public directory, with added segments.
48 | def public_path_for(type, *segments)
49 | ::MerbScrewUnit.public_path_for(type, *segments)
50 | end
51 |
52 | # Construct an app-level path.
53 | #
54 | # @param The type of component.
55 | # @param *segments Path segments to append.
56 | #
57 | # @return
58 | # A path within the host application, with added segments.
59 | def app_path_for(type, *segments)
60 | ::MerbScrewUnit.app_path_for(type, *segments)
61 | end
62 |
63 | # Construct a slice-level path.
64 | #
65 | # @param The type of component.
66 | # @param *segments Path segments to append.
67 | #
68 | # @return
69 | # A path within the slice source (Gem), with added segments.
70 | def slice_path_for(type, *segments)
71 | ::MerbScrewUnit.slice_path_for(type, *segments)
72 | end
73 |
74 | end
75 | end
76 | end
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/screw.builder.js:
--------------------------------------------------------------------------------
1 | var Screw = (function($) {
2 | var screw = {
3 | Unit: function(fn) {
4 | var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
5 | var fn = new Function("matchers", "specifications",
6 | "with (specifications) { with (matchers) { " + contents + " } }"
7 | );
8 |
9 | $(Screw).queue(function() {
10 | Screw.Specifications.context.push($('body > .describe'));
11 | fn.call(this, Screw.Matchers, Screw.Specifications);
12 | Screw.Specifications.context.pop();
13 | $(this).dequeue();
14 | });
15 | },
16 |
17 | Specifications: {
18 | context: [],
19 |
20 | describe: function(name, fn) {
21 | var describe = $('')
22 | .append($('').text(name))
23 | .append('')
24 | .append('')
25 | .append('')
26 | .append('');
27 |
28 | this.context.push(describe);
29 | fn.call();
30 | this.context.pop();
31 |
32 | this.context[this.context.length-1]
33 | .children('.describes')
34 | .append(describe);
35 | },
36 |
37 | it: function(name, fn) {
38 | var it = $('- ')
39 | .append($('
').text(name))
40 | .data('screwunit.run', fn);
41 |
42 | this.context[this.context.length-1]
43 | .children('.its')
44 | .append(it);
45 | },
46 |
47 | before: function(fn) {
48 | var before = $('
- ')
49 | .data('screwunit.run', fn);
50 |
51 | this.context[this.context.length-1]
52 | .children('.befores')
53 | .append(before);
54 | },
55 |
56 | after: function(fn) {
57 | var after = $('
- ')
58 | .data('screwunit.run', fn);
59 |
60 | this.context[this.context.length-1]
61 | .children('.afters')
62 | .append(after);
63 | }
64 | }
65 | };
66 |
67 | $(screw).queue(function() { $(screw).trigger('loading') });
68 | $(function() {
69 | $('
')
70 | .append('
')
71 | .append('')
72 | .append('')
73 | .append('')
74 | .appendTo('body');
75 |
76 | $(screw).dequeue();
77 |
78 | $("#dom")[0].onload = function() {
79 | setTimeout(function() {
80 | $(screw).trigger('loaded');
81 | }, 100);
82 | };
83 | });
84 | return screw;
85 | })(jQuery);
--------------------------------------------------------------------------------
/merb_activerecord/lib/merb/orms/active_record/connection.rb:
--------------------------------------------------------------------------------
1 | require 'fileutils'
2 |
3 | module Merb
4 | module Orms
5 | module ActiveRecord
6 |
7 | # Start a transaction.
8 | #
9 | # Used by Merb::Rack::Console#open_sandbox!
10 | def self.open_sandbox!
11 | ::ActiveRecord::Base.send :increment_open_transactions
12 | ::ActiveRecord::Base.connection.begin_db_transaction
13 | end
14 |
15 | # Rollback a transaction.
16 | #
17 | # Used by Merb::Rack::Console#close_sandbox!
18 | def self.close_sandbox!
19 | ::ActiveRecord::Base.connection.rollback_db_transaction
20 | ::ActiveRecord::Base.send :decrement_open_transactions
21 | end
22 |
23 | class << self
24 | def config_file() Merb.dir_for(:config) / "database.yml" end
25 | def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
26 | def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
27 |
28 | def copy_sample_config
29 | FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
30 | end
31 |
32 | def config
33 | #If Merb#runs_like specifies a differnt db env, use it.
34 | env_sym = (Merb.environment_info.nil?) ?
35 | Merb.environment.to_sym :
36 | Merb.environment_info[:db_env].to_sym
37 |
38 | raise ArgumentError, "missing environment :#{Merb.environment} in config file #{config_file}" unless configurations.key?(env_sym)
39 | @config ||= (Merb::Plugins.config[:merb_active_record] = configurations[env_sym])
40 | end
41 |
42 | def configurations
43 | @configurations ||=
44 | begin
45 | #A proc that will recursively intern(a.k.a symbolize) the keys of the hash
46 | intern_keys = lambda { |x|
47 | x.inject({}) do |y, (k,v)|
48 | y[k.to_sym || k] = v.is_a?(Hash) ? intern_keys.call(v) : v
49 | y
50 | end
51 | }
52 | intern_keys.call(Erubis.load_yaml_file(config_file))
53 | end
54 | end
55 |
56 | # Database connects as soon as the gem is loaded
57 | def connect
58 | if File.exists?(config_file)
59 | Merb.logger.info!("Connecting to database...")
60 |
61 | Thread.new{ loop{ sleep(60*60); ::ActiveRecord::Base.verify_active_connections! } }
62 |
63 | ::ActiveRecord::Base.logger = Merb.logger
64 | ::ActiveRecord::Base.configurations = configurations
65 | ::ActiveRecord::Base.establish_connection config
66 | else
67 | copy_sample_config
68 | Merb.logger.error! "No database.yml file found in #{Merb.root}/config."
69 | Merb.logger.error! "A sample file was created called database.yml.sample for you to copy and edit."
70 | exit(1)
71 | end
72 | end
73 |
74 | end
75 | end
76 | end
77 | end
78 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/screw.behaviors.js:
--------------------------------------------------------------------------------
1 | (function($) {
2 | $(Screw).bind('loaded', function() {
3 | $('.status').fn({
4 | display: function() {
5 | $(this).text(
6 | $('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)'
7 | );
8 | }
9 | });
10 |
11 | $('.describe').fn({
12 | parent: function() {
13 | return $(this).parent('.describes').parent('.describe');
14 | },
15 |
16 | run_befores: function() {
17 | $(this).fn('parent').fn('run_befores');
18 | $(this).children('.befores').children('.before').fn('run');
19 | },
20 |
21 | run_afters: function() {
22 | $(this).fn('parent').fn('run_afters');
23 | $(this).children('.afters').children('.after').fn('run');
24 | },
25 |
26 | enqueue: function() {
27 | $(this).children('.its').children('.it').fn('enqueue');
28 | $(this).children('.describes').children('.describe').fn('enqueue');
29 | },
30 |
31 | selector: function() {
32 | return $(this).fn('parent').fn('selector')
33 | + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
34 | }
35 | });
36 |
37 | $('body > .describe').fn({
38 | selector: function() { return 'body > .describe' }
39 | });
40 |
41 | $('.it').fn({
42 | parent: function() {
43 | return $(this).parent('.its').parent('.describe');
44 | },
45 |
46 | run: function() {
47 | try {
48 | try {
49 | $(this).fn('parent').fn('run_befores');
50 | $(this).data('screwunit.run')();
51 | } finally {
52 | $(this).fn('parent').fn('run_afters');
53 | }
54 | $(this).trigger('passed');
55 | } catch(e) {
56 | $(this).trigger('failed', [e]);
57 | }
58 | },
59 |
60 | enqueue: function() {
61 | var self = $(this).trigger('enqueued');
62 | $(Screw)
63 | .queue(function() {
64 | self.fn('run');
65 | setTimeout(function() { $(Screw).dequeue() }, 0);
66 | });
67 | },
68 |
69 | selector: function() {
70 | return $(this).fn('parent').fn('selector')
71 | + ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
72 | }
73 | });
74 |
75 | $('.before').fn({
76 | run: function() { $(this).data('screwunit.run')() }
77 | });
78 |
79 | $('.after').fn({
80 | run: function() { $(this).data('screwunit.run')() }
81 | });
82 |
83 | $(Screw).trigger('before');
84 | var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
85 | $(to_run)
86 | .focus()
87 | .eq(0).trigger('scroll').end()
88 | .fn('enqueue');
89 | $(Screw).queue(function() { $(Screw).trigger('after') });
90 | })
91 | })(jQuery);
92 |
--------------------------------------------------------------------------------
/merb_screw_unit/lib/merb_screw_unit.rb:
--------------------------------------------------------------------------------
1 | if defined?(Merb::Plugins)
2 |
3 | module Spec; end
4 |
5 | $:.unshift File.dirname(__FILE__)
6 |
7 | load_dependency 'merb-slices'
8 | load_dependency 'merb-assets'
9 | require 'md5'
10 |
11 | Merb::Plugins.add_rakefiles "merb_screw_unit/merbtasks", "merb_screw_unit/slicetasks"
12 |
13 | # Register the Slice for the current host application
14 | Merb::Slices::register(__FILE__)
15 |
16 | # Slice configuration - set this in a before_app_loads callback.
17 | # By default a Slice uses its own layout, so you can swicht to
18 | # the main application layout or no layout at all if needed.
19 | #
20 | # Configuration options:
21 | # :layout - the layout to use; defaults to :merb_screw_unit
22 | # :mirror - which path component types to use on copy operations; defaults to all
23 | Merb::Slices::config[:merb_screw_unit][:layout] ||= :merb_screw_unit
24 |
25 | # All Slice code is expected to be namespaced inside a module
26 | module MerbScrewUnit
27 |
28 | # Slice metadata
29 | self.description = "MerbScrewUnit is a chunky Merb slice!"
30 | self.version = "0.0.1"
31 | self.author = "YOUR NAME"
32 |
33 | # Stub classes loaded hook - runs before LoadClasses BootLoader
34 | # right after a slice's classes have been loaded internally.
35 | def self.loaded
36 | end
37 |
38 | # Initialization hook - runs before AfterAppLoads BootLoader
39 | def self.init
40 | end
41 |
42 | # Activation hook - runs after AfterAppLoads BootLoader
43 | def self.activate
44 | end
45 |
46 | # Deactivation hook - triggered by Merb::Slices.deactivate(MerbScrewUnit)
47 | def self.deactivate
48 | end
49 |
50 | # Setup routes inside the host application
51 | #
52 | # @param scope
53 | # Routes will be added within this scope (namespace). In fact, any
54 | # router behaviour is a valid namespace, so you can attach
55 | # routes at any level of your router setup.
56 | #
57 | # @note prefix your named routes with :merb_screw_unit_
58 | # to avoid potential conflicts with global named routes.
59 | def self.setup_router(scope)
60 | # example of a named route
61 | scope.match('/index.:format').to(:controller => 'main', :action => 'index').name(:merb_screw_unit_index)
62 | scope.match('/:controller/:action')
63 | end
64 |
65 | end
66 |
67 | # Setup the slice layout for MerbScrewUnit
68 | #
69 | # Use MerbScrewUnit.push_path and MerbScrewUnit.push_app_path
70 | # to set paths to merb_screw_unit-level and app-level paths. Example:
71 | #
72 | # MerbScrewUnit.push_path(:application, MerbScrewUnit.root)
73 | # MerbScrewUnit.push_app_path(:application, Merb.root / 'slices' / 'merb_screw_unit')
74 | # ...
75 | #
76 | # Any component path that hasn't been set will default to MerbScrewUnit.root
77 | #
78 | # Or just call setup_default_structure! to setup a basic Merb MVC structure.
79 | MerbScrewUnit.setup_default_structure!
80 |
81 | # Add dependencies for other MerbScrewUnit classes below. Example:
82 | # dependency "merb_screw_unit/other"
83 |
84 | end
--------------------------------------------------------------------------------
/merb_sequel/lib/merb/orms/sequel/connection.rb:
--------------------------------------------------------------------------------
1 | require "fileutils"
2 | require "sequel"
3 |
4 | module Merb
5 | module Orms
6 | module Sequel
7 |
8 | class << self
9 |
10 | def config_file() Merb.dir_for(:config) / "database.yml" end
11 | def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
12 | def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
13 |
14 | def copy_sample_config
15 | FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
16 | end
17 |
18 | def config
19 | @config ||= begin
20 | # Convert string keys to symbols
21 | full_config = Erubis.load_yaml_file(config_file)
22 | config = (Merb::Plugins.config[:merb_sequel] = {})
23 | (full_config[Merb.environment.to_sym] || full_config[Merb.environment] || full_config[:development]).each do |key, value|
24 | config[key.to_sym] = value
25 | end
26 | config
27 | end
28 | end
29 |
30 | # Database connects as soon as the gem is loaded
31 | def connect
32 | if File.exists?(config_file)
33 | Merb.logger.info!("Connecting to the '#{config[:database]}' database on '#{config[:host]}' using '#{config[:adapter]}' ...")
34 | connection = ::Sequel.connect(config_options(config))
35 | begin
36 | connection.test_connection
37 | rescue => e
38 | Merb.logger.error!("Connection Error: #{e}")
39 | exit(1)
40 | end
41 | connection
42 | else
43 | copy_sample_config
44 | Merb.logger.set_log(STDERR)
45 | Merb.logger.error! "No database.yml file found at #{config_file}."
46 | Merb.logger.error! "A sample file was created called #{sample_dest} for you to copy and edit."
47 | exit(1)
48 | end
49 | end
50 |
51 | def config_options(config = {})
52 | options = {}
53 |
54 | # Use SQLite by default
55 | options[:adapter] = (config[:adapter] || "sqlite")
56 | # Use localhost as default host
57 | options[:host] = (config[:host] || "localhost")
58 | # Default user is an empty string. Both username and user keys are supported.
59 | options[:user] = (config[:username] || config[:user] || "")
60 |
61 | options[:password] = config[:password] || ""
62 |
63 | # Both encoding and charset options are supported, default is utf8
64 | options[:encoding] = (config[:encoding] || config[:charset] || "utf8")
65 | # Default database is hey_dude_configure_your_database
66 | options[:database] = config[:database] || "hey_dude_configure_your_database"
67 | # MSSQL support
68 | options[:db_type] = config[:db_type] if config[:db_type]
69 | options[:socket] = config[:socket] if config[:socket]
70 | options[:logger] = Merb.logger
71 | options
72 | end
73 |
74 | end
75 |
76 | end
77 |
78 | end
79 |
80 | end
81 |
--------------------------------------------------------------------------------
/merb_sequel/lib/merb_sequel/merbtasks.rb:
--------------------------------------------------------------------------------
1 | require "fileutils"
2 |
3 | namespace :sequel do
4 |
5 | desc "Minimalistic Sequel environment"
6 | task :sequel_env do
7 | Merb::Orms::Sequel.connect
8 | end
9 |
10 | namespace :db do
11 |
12 | desc "Perform migration using migrations in schema/migrations"
13 | task :migrate => :sequel_env do
14 | Sequel::Migrator.apply(Sequel::Model.db, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
15 | end
16 |
17 | desc "Drop all tables and perform migrations"
18 | task :reset => :sequel_env do
19 | Sequel::Model.db.drop_table *Sequel::Model.db.tables
20 | Sequel::Migrator.apply(Sequel::Model.db, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
21 | end
22 |
23 | desc "Create the database according to the config from the database.yaml. Use [username,password] if you need another user to connect to DB than in config."
24 | task :create, :username, :password do |t,args|
25 | config = Merb::Orms::Sequel.config
26 | puts "Creating database '#{config[:database]}'"
27 | case config[:adapter]
28 | when 'postgres'
29 | if args.username.nil?
30 | `createdb -U #{config[:username]} #{config[:database]}`
31 | else
32 | `createdb -U #{args.username} -O #{config[:username]} #{config[:database]}`
33 | end
34 | when 'mysql'
35 | `mysqladmin -u #{config[:username]} #{config[:password] ? "-p'#{config[:password]}'" : ''} create #{config[:database]}`
36 | else
37 | raise "Adapter #{config[:adapter]} not supported for creating databases yet."
38 | end
39 | end
40 |
41 | desc "Drop the database for enviroment from database.yaml (postgres only). Use [username,password] if you need another user to connect to DB than in config."
42 | task :drop, :username, :password do |t,args|
43 | config = Merb::Orms::Sequel.config
44 | user = args.username.nil? ? config[:username]: args.username
45 | puts "Droping database '#{config[:database]}'"
46 | case config[:adapter]
47 | when 'postgres'
48 | `dropdb -U #{user} #{config[:database]}`
49 | else
50 | raise "Adapter #{config[:adapter]} not supported for dropping databases yet."
51 | end
52 | end
53 |
54 | desc "Truncate all tables in database"
55 | task :truncate => :sequel_env do
56 | db = Sequel::Model.db
57 | db << "TRUNCATE #{db.tables.join(', ')} CASCADE;"
58 | end
59 | end
60 |
61 | namespace :sessions do
62 |
63 | desc "Creates session migration"
64 | task :create => :sequel_env do
65 | migration_exists = Dir[File.join(Merb.root,"schema", "migrations", "*.rb")].detect{ |f| f =~ /database_sessions\.rb/ }
66 | if migration_exists
67 | puts "\nThe Session Migration File already exists\n\n"
68 | else
69 | sh %{merb-gen session_migration}
70 | end
71 | end
72 |
73 | desc "Clears sessions"
74 | task :clear => :sequel_env do
75 | table_name = ((Merb::Plugins.config[:sequel] || {})[:session_table_name] || "sessions")
76 | Sequel::Model.db.connect.execute("DELETE FROM #{table_name}")
77 | end
78 |
79 | end
80 |
81 | end
82 |
--------------------------------------------------------------------------------
/merb_parts/spec/merb-parts_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
3 | describe "A Merb PartController" do
4 |
5 | before(:each) do
6 | Merb::Router.prepare do |r|
7 | r.default_routes
8 | end
9 | end
10 |
11 | it "should render a part template with no layout" do
12 | controller = dispatch_to(Main, :index2)
13 | controller.body.should ==
14 | "TODOPART\nDo this|Do that|Do the other thing\nTODOPART"
15 | end
16 |
17 | it "should render a part template with it's own layout" do
18 | controller = dispatch_to(Main, :index)
19 | controller.body.should ==
20 | "TODOLAYOUT\nTODOPART\nDo this|Do that|Do the other thing\nTODOPART\nTODOLAYOUT"
21 | end
22 |
23 | it "should render multiple parts if more then one part is passed in" do
24 | controller = dispatch_to(Main, :index3)
25 | controller.body.should ==
26 | "TODOPART\nDo this|Do that|Do the other thing\nTODOPART" +
27 | "TODOLAYOUT\nTODOPART\nDo this|Do that|Do the other thing\nTODOPART\nTODOLAYOUT"
28 | end
29 |
30 | it "should render the html format by default to the controller that set it" do
31 | controller = dispatch_to(Main, :index4)
32 | controller.body.should match(/part_html_format/m)
33 | end
34 |
35 | it "should render the xml format according to the controller" do
36 | controller = dispatch_to(Main, :index4, {:format => 'xml'} )
37 | controller.body.should match(/part_xml_format/m)
38 | end
39 |
40 | it "should render the js format according to the controller" do
41 | controller = dispatch_to(Main, :index4, :format => 'js')
42 | controller.body.should match(/part_js_format/m)
43 | end
44 |
45 | it "should provide params when calling a part" do
46 | controller = dispatch_to(Main, :part_with_params)
47 | controller.body.should match( /my_param = my_value/)
48 | end
49 |
50 | it "should provide arrays from params when calling a part" do
51 | controller = dispatch_to(Main, :part_with_arrays_in_params)
52 | controller.body.should match(/my_param = my_first_value, my_second_value/)
53 | end
54 |
55 | it "should render from inside a view" do
56 | controller = dispatch_to(Main, :part_within_view)
57 | controller.body.should match( /Do this/)
58 | end
59 |
60 | it "should render a template from an absolute path" do
61 | controller = dispatch_to(Main, :parth_with_absolute_template)
62 | controller.body.should match(/part_html_format/m)
63 | end
64 |
65 | end
66 |
67 | describe "A Merb Part Controller with urls" do
68 |
69 | def new_url_controller(route, params = {:action => 'show', :controller => 'Test'})
70 | @controller = dispatch_to(Main, :index)
71 | TodoPart.new(@controller)
72 | end
73 |
74 | it "should use the web_controllers type if no controller is specified" do
75 | c = new_url_controller(@default_route, :controller => "my_controller")
76 | the_url = c.url(:action => "bar")
77 | the_url.should == "/main/bar"
78 | end
79 |
80 | end
81 |
82 | describe "A Merb Part Controller inheriting from another Part Controller" do
83 |
84 | it "should inherit the _template_root" do
85 | TodoPart._template_root.should == File.expand_path(File.dirname(__FILE__) / 'fixtures' / 'parts' / 'views')
86 | TodoPart._template_root.should == DonePart._template_root
87 | end
88 |
89 | end
--------------------------------------------------------------------------------
/merb_sequel/lib/merb/session/sequel_session.rb:
--------------------------------------------------------------------------------
1 | require 'sequel'
2 | require 'merb-core/dispatch/session'
3 | require 'base64'
4 |
5 | module Merb
6 |
7 | Merb::Plugins.config[:merb_sequel][:session_table_name] ||= "sessions"
8 |
9 | # Default session migration run if a sessions table does not yet exist.
10 | #
11 | # Will create a table with a name of 'sessions' by default, or as
12 | # set by Merb::Plugins.config[:merb_sequel][:session_table_name]
13 |
14 | class CreateSessionMigration < Sequel::Migration
15 | def up
16 | table_name = Merb::Plugins.config[:merb_sequel][:session_table_name].to_sym
17 | unless table_exists?(table_name)
18 | puts "Warning: The database did not contain a '#{table_name}' table for sessions."
19 |
20 | create_table table_name do
21 | primary_key :id
22 | varchar :session_id
23 | text :data
24 | timestamp :created_at
25 | end
26 |
27 | puts "Created '#{table_name}' session table."
28 | end
29 | end
30 | end
31 |
32 | CreateSessionMigration.apply(Sequel::Model.db, :up)
33 |
34 | # Sessions stored in Sequel model.
35 | #
36 | # To use Sequel based sessions add the following to config/init.rb:
37 | #
38 | # Merb::Config[:session_store] = 'sequel'
39 |
40 | class SequelSessionStore < Sequel::Model(Merb::Plugins.config[:merb_sequel][:session_table_name].to_sym)
41 |
42 | class << self
43 |
44 | # ==== Parameters
45 | # session_id:: ID of the session to retrieve.
46 | #
47 | # ==== Returns
48 | # ContainerSession:: The session corresponding to the ID.
49 | def retrieve_session(session_id)
50 | if item = find(:session_id => session_id)
51 | item.data
52 | end
53 | end
54 |
55 | # ==== Parameters
56 | # session_id:: ID of the session to set.
57 | # data:: The session to set.
58 | def store_session(session_id, data)
59 | if item = find(:session_id => session_id)
60 | item.update(:data => data)
61 | else
62 | create(:session_id => session_id, :data => data, :created_at => Time.now)
63 | end
64 | end
65 |
66 | # ==== Parameters
67 | # session_id:: ID of the session to delete.
68 | def delete_session(session_id)
69 | if item = find(:session_id => session_id)
70 | item.delete
71 | end
72 | end
73 |
74 | # ==== Returns
75 | # Integer:: The maximum length of the 'data' column.
76 | def data_column_size_limit
77 | 512 # TODO - figure out how much space we actually have
78 | end
79 |
80 | alias :create_table! :create_table
81 | alias :drop_table! :drop_table
82 | end
83 |
84 | # Lazy-unserialize session state.
85 | def data
86 | @data ||= (@values[:data] ? Marshal.load(@values[:data]) : {})
87 | end
88 |
89 | # Virtual attribute writer - override.
90 | def data=(hsh)
91 | @data = hsh if hsh.is_a?(Hash)
92 | end
93 |
94 | # Has the session been loaded yet?
95 | def loaded?
96 | !!@data
97 | end
98 |
99 | before_save do
100 | @values[:data] = Marshal.dump(self.data)
101 | if @values[:data].size > self.class.data_column_size_limit
102 | raise Merb::SessionMixin::SessionOverflow
103 | end
104 | end
105 |
106 | end
107 |
108 | class SequelSession < SessionStoreContainer
109 |
110 | # The session store type
111 | self.session_store_type = :sequel
112 |
113 | # The store object is the model class itself
114 | self.store = SequelSessionStore
115 |
116 | end
117 |
118 | end
119 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/jquery.print.js:
--------------------------------------------------------------------------------
1 | (function($) {
2 |
3 | function print_array(obj, opts) {
4 | var result = [];
5 | for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
6 | result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
7 |
8 | if (obj.length > opts.max_array)
9 | result.push((obj.length - opts.max_array) + ' more...');
10 | if (result.length == 0) return "[]"
11 | return "[ " + result.join(", ") + " ]";
12 | }
13 |
14 | function print_element(obj) {
15 | if (obj.nodeType == 1) {
16 | var result = [];
17 | var properties = [ 'className', 'id' ];
18 | var extra = {
19 | 'input': ['type', 'name', 'value'],
20 | 'a': ['href', 'target'],
21 | 'form': ['method', 'action']
22 | };
23 | $.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function() {
24 | if (obj[this])
25 | result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
26 | });
27 | return "<" + obj.tagName.toLowerCase()
28 | + result.join('') + ">";
29 | }
30 | }
31 |
32 | function print_object(obj, opts) {
33 | var seen = opts.seen || [];
34 |
35 | var result = [], key, value;
36 | for (var k in obj) {
37 | if (obj.hasOwnProperty(k) && $.inArray(obj[k], seen) < 0) {
38 | seen.push(obj[k]);
39 | value = $.print(obj[k], $.extend({}, opts, { max_array: 6, max_string: 40, seen: seen }));
40 | } else
41 | value = "...";
42 | result.push(k + ": " + value);
43 | }
44 | if (result.length == 0) return "{}";
45 | return "{ " + result.join(", ") + " }";
46 | }
47 |
48 | function print_jquery(obj) {
49 | }
50 |
51 | function print_string(value, opts) {
52 | var character_substitutions = {
53 | '\b': '\\b',
54 | '\t': '\\t',
55 | '\n': '\\n',
56 | '\f': '\\f',
57 | '\r': '\\r',
58 | '"' : '\\"',
59 | '\\': '\\\\'
60 | };
61 | var r = /["\\\x00-\x1f\x7f-\x9f]/g;
62 |
63 | var str = r.test(value)
64 | ? '"' + value.replace(r, function (a) {
65 | var c = character_substitutions[a];
66 | if (c) return c;
67 | c = a.charCodeAt();
68 | return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
69 | }) + '"'
70 | : '"' + value + '"';
71 | if (str.length > opts.max_string)
72 | return str.slice(0, opts.max_string + 1) + '..."';
73 | else
74 | return str;
75 | }
76 |
77 | $.print = function(obj, options) {
78 | var opts = $.extend({}, { max_array: 10, max_string: 100 }, options);
79 |
80 | if (typeof obj == 'undefined')
81 | return "undefined";
82 | else if (typeof obj == 'boolean')
83 | return obj.toString();
84 | else if (!obj && typeof obj == 'number')
85 | return 'NaN';
86 | else if (!obj)
87 | return "null";
88 | else if (typeof obj == 'string')
89 | return print_string(obj, opts);
90 | else if (obj instanceof RegExp)
91 | return obj.toString();
92 | else if (typeof obj == 'function' || obj instanceof Function)
93 | return obj.toString().match(/^([^)]*\))/)[1];
94 | else if (obj instanceof Array)
95 | return print_array(obj, opts);
96 | else if (obj.nodeType)
97 | return print_element(obj);
98 | else if (obj.jquery)
99 | if(obj.length)
100 | return "$(" + $.print(obj.get()) + ")";
101 | else
102 | return "$(\"" + obj.selector + "\")";
103 | else if (obj instanceof Error)
104 | return print_object(obj, $.extend({}, options, { max_string: 200 }));
105 | else if (obj instanceof Object)
106 | return print_object(obj, opts);
107 | else
108 | return obj.toString().replace(/\n\s*/g, '');
109 | }
110 |
111 | })(jQuery);
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/screw.matchers.js:
--------------------------------------------------------------------------------
1 | Screw.Matchers = (function($) {
2 | var jquerize = function(obj) {
3 | if(typeof obj == "string") return iframeWindow.$(obj);
4 | else return obj;
5 | }
6 |
7 | return matchers = {
8 | expect: function(actual) {
9 | return {
10 | to: function(matcher, expected, not) {
11 | var matched = matcher.match(expected, actual);
12 | if (not ? matched : !matched) {
13 | throw(matcher.failure_message(expected, actual, not));
14 | }
15 | },
16 |
17 | to_not: function(matcher, expected) {
18 | this.to(matcher, expected, true);
19 | }
20 | }
21 | },
22 |
23 | exist: {
24 | match: function(expected, actual) {
25 | return actual.length > 0;
26 | },
27 | failure_message: function(expected, actual, not) {
28 | return 'expected ' + $.print(actual) + (not ? ' to not ' : ' to ') + "exist";
29 | }
30 | },
31 |
32 | contain_text: {
33 | match: function(expected, actual) {
34 | return jquerize(actual).filter(":contains(\"" + expected + "\")").length > 0;
35 | },
36 | failure_message: function(expected, actual, not) {
37 | return 'expected ' + $.print(jquerize(actual)) + (not ? ' to not have ' : ' to have ') + $.print(expected);
38 | }
39 | },
40 | have: {
41 | match: function(expected, actual) {
42 | return jquerize(actual).find(expected).length > 0;
43 | },
44 | failure_message: function(expected, actual, not) {
45 | return 'expected ' + $.print(jquerize(actual)) + (not ? ' to not have ' : ' to have ') + $.print(expected);
46 | }
47 | },
48 | be_visible: {
49 | match: function(expected, actual) {
50 | return jquerize(actual).is(":visible");
51 | },
52 | failure_message: function(expected, actual, not) {
53 | return 'expected ' + $.print(jquerize(actual)) + (not ? ' to not ' : ' to ') + "be visible";
54 | }
55 | },
56 |
57 | equal: {
58 | match: function(expected, actual) {
59 | if (expected instanceof Array) {
60 | for (var i = 0; i < actual.length; i++)
61 | if (!Screw.Matchers.equal.match(expected[i], actual[i])) return false;
62 | return actual.length == expected.length;
63 | } else if (expected instanceof Object) {
64 | for (var key in expected)
65 | if (expected[key] != actual[key]) return false;
66 | for (var key in actual)
67 | if (actual[key] != expected[key]) return false;
68 | return true;
69 | } else {
70 | return expected == actual;
71 | }
72 | },
73 |
74 | failure_message: function(expected, actual, not) {
75 | return 'expected ' + $.print(actual) + (not ? ' to not equal ' : ' to equal ') + $.print(expected);
76 | }
77 | },
78 |
79 | match: {
80 | match: function(expected, actual) {
81 | if (expected.constructor == RegExp)
82 | return expected.exec(actual.toString());
83 | else
84 | return actual.indexOf(expected) > -1;
85 | },
86 |
87 | failure_message: function(expected, actual, not) {
88 | return 'expected ' + $.print(actual) + (not ? ' to not match ' : ' to match ') + $.print(expected);
89 | }
90 | },
91 |
92 | be_empty: {
93 | match: function(expected, actual) {
94 | if (jquerize(actual).length == undefined)
95 | throw($.print(jquerize(actual)) + " does not respond to length");
96 |
97 | return actual.length == 0;
98 | },
99 |
100 | failure_message: function(expected, actual, not) {
101 | return 'expected ' + $.print(jquerize(actual)) + (not ? ' to not be empty' : ' to be empty');
102 | }
103 | }
104 | }
105 | })(jQuery);
--------------------------------------------------------------------------------
/CHANGELOG:
--------------------------------------------------------------------------------
1 | == 0.9.2 "appropriate response to reality" 2008-03-24
2 | * have select_control use database value as the default selected value
3 | * windows support in rakefile
4 | * Session should respond to each_with_index
5 | * merb-gen fix for namespaced resources
6 | * fix rakefiles in plugins. Fix merb_sequel and Merb-datamapper and merb_activerecord to use autoflush logging so log messages are immediately flushed instead of showing nothing.
7 | * Updated format of migrations to ActiveRecord 2.0 style
8 | * Minor cleanup and comment about using the assistance instead of my custom extensions...
9 | * Time_ago_in_words and spec for her
10 | * Initial stab at some date_time helpers up in here...
11 | * Implementation of IRB sandbox methods
12 | * added better error message when a database can't be created
13 | * fixed rake db:test:clone
14 | * fixed bug when using custom charset and collation in database.yml
15 | * Merb.logger is now correctly setup from Merb::Config for :merb_start task
16 | * Make helper specs pass again. NOTE: Config specs do not work.
17 | * ORM plugins (AR, DM, Sequel) now hook into the BootLoader
18 | * cleaned up the existing rake tasks + added rake db:drop:all, rake db:migrate:redo, rake db:migrate:reset + rake db:reset now drops your dbs, recreate them and load schema.rb + rake db:rollback + rake db:abort_if_pending_migrations
19 | * Changed merb active record rake tasks to create utf8 dabases when using rake db:create / db:reset Added rake db:charset rake db:collation Support for charset/collation arguments: rake db:create CHARSET=latin1, COLLATION=latin1_bin
20 | * cleaned up the existing rake tasks + added rake db:drop:all, rake db:migrate:redo, rake db:migrate:reset + rake db:reset now drops your dbs, recreate them and load schema.rb + rake db:rollback + rake db:abort_if_pending_migrations
21 | * Changed merb active record rake tasks to create utf8 dabases when using rake db:create / db:reset
22 | * fix rakefile to not build merb_rspec as it is in -core now.
23 | * Using autoload to connect to the database on the first use of DataMapper
24 | * Corrects some issues with merb_test_unit
25 | * Adding updated_at for DM sessions.
26 |
27 | == 0.9.1 "Some are half-wild, and some are just outlaws." 2008-02-29
28 | * merb_activerecord: updated render syntax in new action of db plugin
29 | resource_controller controller templates.
30 | * merb_activerecord: renamed sample yml files for orm db config as
31 | .yml.sample; added install:orm rake task
32 | * merb_activerecord: Replace calls to puts with Merb.logger
33 | * merb_activerecord: expiry time was not being passed in properly for both
34 | sequel and active_record
35 | * merb_datamapper: updated render syntax in new action of db plugin
36 | resource_controller controller templates.
37 | * merb_datamapper: Added to_param method for data_mapper
38 | * merb_datamapper: merb_dm casts port to an integer
39 | * merb_datamapper: renamed sample yml files for orm db config as .yml.sample;
40 | added install:orm rake task
41 | * merb_datamapper: Replace calls to puts with Merb.logger
42 | * merb_helpers: Escape characters in form control values
43 | * merb_helpers: Let error_messages_for actually use the custom error lambda
44 | * merb_helpers: helpers has no tasks
45 | * merb_helpers: Better variable names in errors_messages_for.
46 | * merb_helpers: Added examples for error_messages_for, and other cleanups.
47 | * merb_rspec: removed duplicate includes for the matchers, this has moved to merb-core
48 | * merb_sequel: updated render syntax in new action of db plugin
49 | resource_controller controller templates.
50 | * merb_sequel: renamed sample yml files for orm db config as .yml.sample;
51 | added install:orm rake task
52 | * merb_sequel: rearranging the merbtasks files in all plugins
53 | * merb_sequel: expiry time was not being passed in properly for both sequel
54 | and active_record
55 | * merb_test_unit: Adding rspec dependency to merb_rspec, removing merb-test
56 | references in merb_test_unit
57 | * merb_test_unit: moving plugin rakefiles into a plugin name parent folder
58 | * merb_test_unit: Normalize calls to Merb.start
59 |
--------------------------------------------------------------------------------
/merb_parts/lib/merb_parts/part_controller.rb:
--------------------------------------------------------------------------------
1 | require File.join(File.dirname(__FILE__), "mixins", "web_controller")
2 | module Merb
3 |
4 | # A Merb::PartController is a light weight way to share logic and templates
5 | # amongst controllers.
6 | # Merb::PartControllers work just like Merb::controller.
7 | # There is a filter stack, layouts (if needed) all the render functions,
8 | # and url generation.
9 | #
10 | # Cookies, params, and even the request object are shared with the web controller
11 | class PartController < AbstractController
12 | include Merb::Mixins::WebController
13 |
14 | attr_reader :params
15 |
16 | cattr_accessor :_subclasses
17 | self._subclasses = Set.new
18 |
19 | # ==== Returns
20 | # Array[Class]:: Classes that inherit from Merb::PartController.
21 | def self.subclasses_list() _subclasses end
22 |
23 | # ==== Parameters
24 | # action<~to_s>:: The name of the action that will be rendered.
25 | # type<~to_s>::
26 | # The mime-type of the template that will be rendered. Defaults to html.
27 | # controller<~to_s>::
28 | # The name of the controller that will be rendered. Defaults to
29 | # controller_name.
30 | #
31 | # ==== Returns
32 | # String:: The template location, i.e. ":controller/:action.:type".
33 | def _template_location(action, type = :html, controller = controller_name)
34 | "#{controller}/#{action}.#{type}"
35 | end
36 |
37 | # The location to look for a template and mime-type. This is overridden
38 | # from AbstractController, which defines a version of this that does not
39 | # involve mime-types.
40 | #
41 | # ==== Parameters
42 | # template::
43 | # The absolute path to a template - without mime and template extension.
44 | # The mime-type extension is optional - it will be appended from the
45 | # current content type if it hasn't been added already.
46 | # type<~to_s>::
47 | # The mime-type of the template that will be rendered. Defaults to nil.
48 | #
49 | # @public
50 | def _absolute_template_location(template, type)
51 | template.match(/\.#{type.to_s.escape_regexp}$/) ? template : "#{template}.#{type}"
52 | end
53 |
54 | # Sets the template root to the default parts view directory.
55 | #
56 | # ==== Parameters
57 | # klass::
58 | # The Merb::PartController inheriting from the base class.
59 | def self.inherited(klass)
60 | _subclasses << klass.to_s
61 | super
62 | klass._template_root = Merb.dir_for(:part) / "views" unless self._template_root
63 | end
64 |
65 | # ==== Parameters
66 | # web_controller:: The controller calling this part.
67 | # opts:: Additional options for this part.
68 | def initialize(web_controller, opts = {})
69 | @web_controller = web_controller
70 | @params = @web_controller.params.dup
71 | @params.merge!(opts) unless opts.empty?
72 | super
73 | @content_type = @web_controller.content_type
74 | end
75 |
76 | # ==== Parameters
77 | # name<~to_sym, Hash>:: The name of the URL to generate.
78 | # rparams:: Parameters for the route generation.
79 | #
80 | # ==== Returns
81 | # String:: The generated URL.
82 | #
83 | # ==== Alternatives
84 | # If a hash is used as the first argument, a default route will be
85 | # generated based on it and rparams.
86 | # ====
87 | # TODO: Update this documentation
88 | def url(name, *args)
89 | args << params
90 | Merb::Router.url(name, *args)
91 | end
92 |
93 | alias_method :relative_url, :url
94 |
95 | # ==== Parameters
96 | # action<~to_s>:: An action to dispatch to. Defaults to :to_s.
97 | #
98 | # ==== Returns
99 | # String:: The part body.
100 | def _dispatch(action=:to_s)
101 | action = action.to_s
102 | self.action_name = action
103 | super(action)
104 | @body
105 | end
106 |
107 | # Send any methods that are missing back up to the web controller
108 | # Patched to set partial locals on the web controller
109 | def method_missing(sym, *args, &blk)
110 | @web_controller.instance_variable_set(:@_merb_partial_locals, @_merb_partial_locals) if @_merb_partial_locals
111 | @web_controller.send(sym, *args, &blk)
112 | end
113 | end
114 | end
115 |
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/metadata.jquery.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Metadata - jQuery plugin for parsing metadata from elements
3 | *
4 | * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
5 | *
6 | * Dual licensed under the MIT and GPL licenses:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | * http://www.gnu.org/licenses/gpl.html
9 | *
10 | * Revision: $Id$
11 | *
12 | */
13 |
14 | /**
15 | * Sets the type of metadata to use. Metadata is encoded in JSON, and each property
16 | * in the JSON will become a property of the element itself.
17 | *
18 | * There are three supported types of metadata storage:
19 | *
20 | * attr: Inside an attribute. The name parameter indicates *which* attribute.
21 | *
22 | * class: Inside the class attribute, wrapped in curly braces: { }
23 | *
24 | * elem: Inside a child element (e.g. a script tag). The
25 | * name parameter indicates *which* element.
26 | *
27 | * The metadata for an element is loaded the first time the element is accessed via jQuery.
28 | *
29 | * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
30 | * matched by expr, then redefine the metadata type and run another $(expr) for other elements.
31 | *
32 | * @name $.metadata.setType
33 | *
34 | * @example This is a p
35 | * @before $.metadata.setType("class")
36 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
37 | * @desc Reads metadata from the class attribute
38 | *
39 | * @example This is a p
40 | * @before $.metadata.setType("attr", "data")
41 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
42 | * @desc Reads metadata from a "data" attribute
43 | *
44 | * @example This is a p
45 | * @before $.metadata.setType("elem", "script")
46 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
47 | * @desc Reads metadata from a nested script element
48 | *
49 | * @param String type The encoding type
50 | * @param String name The name of the attribute to be used to get metadata (optional)
51 | * @cat Plugins/Metadata
52 | * @descr Sets the type of encoding to be used when loading metadata for the first time
53 | * @type undefined
54 | * @see metadata()
55 | */
56 |
57 | (function($) {
58 |
59 | $.extend({
60 | metadata : {
61 | defaults : {
62 | type: 'class',
63 | name: 'metadata',
64 | cre: /({.*})/,
65 | single: 'metadata'
66 | },
67 | setType: function( type, name ){
68 | this.defaults.type = type;
69 | this.defaults.name = name;
70 | },
71 | get: function( elem, opts ){
72 | var settings = $.extend({},this.defaults,opts);
73 | // check for empty string in single property
74 | if ( !settings.single.length ) settings.single = 'metadata';
75 |
76 | var data = $.data(elem, settings.single);
77 | // returned cached data if it already exists
78 | if ( data ) return data;
79 |
80 | data = "{}";
81 |
82 | if ( settings.type == "class" ) {
83 | var m = settings.cre.exec( elem.className );
84 | if ( m )
85 | data = m[1];
86 | } else if ( settings.type == "elem" ) {
87 | if( !elem.getElementsByTagName ) return;
88 | var e = elem.getElementsByTagName(settings.name);
89 | if ( e.length )
90 | data = $.trim(e[0].innerHTML);
91 | } else if ( elem.getAttribute != undefined ) {
92 | var attr = elem.getAttribute( settings.name );
93 | if ( attr )
94 | data = attr;
95 | }
96 |
97 | if ( data.indexOf( '{' ) <0 )
98 | data = "{" + data + "}";
99 |
100 | data = eval("(" + data + ")");
101 |
102 | $.data( elem, settings.single, data );
103 | return data;
104 | }
105 | }
106 | });
107 |
108 | /**
109 | * Returns the metadata object for the first member of the jQuery object.
110 | *
111 | * @name metadata
112 | * @descr Returns element's metadata object
113 | * @param Object opts An object contianing settings to override the defaults
114 | * @type jQuery
115 | * @cat Plugins/Metadata
116 | */
117 | $.fn.metadata = function( opts ){
118 | if(this[0])
119 | return $.metadata.get( this[0], opts );
120 | };
121 |
122 | $.fn.setMetadata = function( val ) {
123 | return this.each(function() {
124 | if(!this) return true;
125 | $.data( this, $.metadata.defaults.single, val );
126 | });
127 | }
128 |
129 | })(jQuery);
--------------------------------------------------------------------------------
/merb_test_unit/specs/controller_asserts_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
3 | class RedirectableTarget
4 | attr_accessor :status, :headers
5 | def initialize; @headers = {}; end
6 | end
7 |
8 | describe Merb::Test::Unit::ControllerAsserts do
9 | before(:each) do
10 | @target = RedirectableTarget.new
11 | end
12 |
13 | describe "#assert_redirect" do
14 | it "should pass on valid redirect codes" do
15 | assert_redirect 301
16 | end
17 |
18 | it "should fail on unused redirect codes" do
19 | lambda{ assert_redirect(333) }.should raise_error(Test::Unit::AssertionFailedError)
20 | end
21 |
22 | it "should fail on non redirect codes" do
23 | lambda{ assert_redirect(200) }.should raise_error(Test::Unit::AssertionFailedError)
24 | end
25 |
26 | it "should pass a target with a valid redirect status" do
27 | @target.status = 301
28 |
29 | assert_redirect @target
30 | end
31 |
32 | it "should fail on a target with an unused redirect status" do
33 | @target.status = 345
34 |
35 | lambda { assert_redirect(@target) }.should raise_error(Test::Unit::AssertionFailedError)
36 | end
37 |
38 | it "should fail on a target with an non redirect status" do
39 | @target.status = 404
40 |
41 | lambda { assert_redirect(@target) }.should raise_error(Test::Unit::AssertionFailedError)
42 | end
43 | end
44 |
45 | describe "#assert_redirect_to" do
46 | it "should pass on a target if the status code is 300 level and the locations match" do
47 | @target.status = 301
48 | @target.headers['Location'] = "http://example.com/"
49 |
50 | assert_redirect_to "http://example.com/", @target
51 | end
52 |
53 | it "should fail on a target if the status code is 300 level but the locations don't match" do
54 | @target.status = 301
55 | @target.headers['Location'] = "http://example.com/"
56 |
57 | lambda { assert_redirect_to("http://localhost/", @target) }.should raise_error(Test::Unit::AssertionFailedError)
58 | end
59 |
60 | it "should fail on a target if the locations match but the status code is not 300 level" do
61 | @target.status = 200
62 | @target.headers['Location'] = "http://example.com/"
63 |
64 | lambda { assert_redirect_to("http://example.com/", @target) }.should raise_error(Test::Unit::AssertionFailedError)
65 | end
66 | end
67 |
68 | describe "#assert_success" do
69 | it "should pass on valid 200 level codes" do
70 | assert_success 200
71 | end
72 |
73 | it "should fail on unused 200 level codes" do
74 | lambda { assert_success 234 }.should raise_error(Test::Unit::AssertionFailedError)
75 | end
76 |
77 | it "should fail on non 200 level code" do
78 | lambda { assert_success 404 }.should raise_error(Test::Unit::AssertionFailedError)
79 | end
80 |
81 | it "should pass a target with a valid 200 level status" do
82 | @target.status = 202
83 |
84 | assert_success @target
85 | end
86 |
87 | it "should fail on a target with an unused 200 level status" do
88 | @target.status = 222
89 |
90 | lambda { assert_success(@target) }.should raise_error(Test::Unit::AssertionFailedError)
91 | end
92 |
93 | it "should fail on a target with an non 200 level status" do
94 | @target.status = 404
95 |
96 | lambda { assert_success(@target) }.should raise_error(Test::Unit::AssertionFailedError)
97 | end
98 | end
99 |
100 | describe "#assert_missing" do
101 | it "should pass on valid 400 level codes" do
102 | assert_missing 400
103 | end
104 |
105 | it "should fail on unused 456 level codes" do
106 | lambda { assert_missing 456 }.should raise_error(Test::Unit::AssertionFailedError)
107 | end
108 |
109 | it "should fail on non 400 level code" do
110 | lambda { assert_missing 301 }.should raise_error(Test::Unit::AssertionFailedError)
111 | end
112 |
113 | it "should pass a target with a valid 400 level status" do
114 | @target.status = 404
115 |
116 | assert_missing @target
117 | end
118 |
119 | it "should fail on a target with an unused 444 level status" do
120 | @target.status = 444
121 |
122 | lambda { assert_missing(@target) }.should raise_error(Test::Unit::AssertionFailedError)
123 | end
124 |
125 | it "should fail on a target with an non 400 level status" do
126 | @target.status = 200
127 |
128 | lambda { assert_missing(@target) }.should raise_error(Test::Unit::AssertionFailedError)
129 | end
130 | end
131 | end
--------------------------------------------------------------------------------
/merb_screw_unit/spec/merb_screw_unit_spec.rb:
--------------------------------------------------------------------------------
1 | require File.dirname(__FILE__) + '/spec_helper'
2 |
3 | describe "MerbScrewUnit (module)" do
4 |
5 | it "should have proper specs"
6 |
7 | # Feel free to remove the specs below
8 |
9 | before :all do
10 | Merb::Router.prepare { |r| r.add_slice(:MerbScrewUnit) } if standalone?
11 | end
12 |
13 | after :all do
14 | Merb::Router.reset! if standalone?
15 | end
16 |
17 | it "should be registered in Merb::Slices.slices" do
18 | Merb::Slices.slices.should include(MerbScrewUnit)
19 | end
20 |
21 | it "should be registered in Merb::Slices.paths" do
22 | Merb::Slices.paths[MerbScrewUnit.name].should == current_slice_root
23 | end
24 |
25 | it "should have an :identifier property" do
26 | MerbScrewUnit.identifier.should == "merb_screw_unit"
27 | end
28 |
29 | it "should have an :identifier_sym property" do
30 | MerbScrewUnit.identifier_sym.should == :merb_screw_unit
31 | end
32 |
33 | it "should have a :root property" do
34 | MerbScrewUnit.root.should == Merb::Slices.paths[MerbScrewUnit.name]
35 | MerbScrewUnit.root_path('app').should == current_slice_root / 'app'
36 | end
37 |
38 | it "should have a :file property" do
39 | MerbScrewUnit.file.should == current_slice_root / 'lib' / 'merb_screw_unit.rb'
40 | end
41 |
42 | it "should have metadata properties" do
43 | MerbScrewUnit.description.should == "MerbScrewUnit is a chunky Merb slice!"
44 | MerbScrewUnit.version.should == "0.0.1"
45 | MerbScrewUnit.author.should == "YOUR NAME"
46 | end
47 |
48 | it "should have :routes and :named_routes properties" do
49 | MerbScrewUnit.routes.should_not be_empty
50 | MerbScrewUnit.named_routes[:merb_screw_unit_index].should be_kind_of(Merb::Router::Route)
51 | end
52 |
53 | it "should have an url helper method for slice-specific routes" do
54 | MerbScrewUnit.url(:controller => 'main', :action => 'show', :format => 'html').should == "/merb_screw_unit/main/show.html"
55 | MerbScrewUnit.url(:merb_screw_unit_index, :format => 'html').should == "/merb_screw_unit/index.html"
56 | end
57 |
58 | it "should have a config property (Hash)" do
59 | MerbScrewUnit.config.should be_kind_of(Hash)
60 | end
61 |
62 | it "should have bracket accessors as shortcuts to the config" do
63 | MerbScrewUnit[:foo] = 'bar'
64 | MerbScrewUnit[:foo].should == 'bar'
65 | MerbScrewUnit[:foo].should == MerbScrewUnit.config[:foo]
66 | end
67 |
68 | it "should have a :layout config option set" do
69 | MerbScrewUnit.config[:layout].should == :merb_screw_unit
70 | end
71 |
72 | it "should have a dir_for method" do
73 | app_path = MerbScrewUnit.dir_for(:application)
74 | app_path.should == current_slice_root / 'app'
75 | [:view, :model, :controller, :helper, :mailer, :part].each do |type|
76 | MerbScrewUnit.dir_for(type).should == app_path / "#{type}s"
77 | end
78 | public_path = MerbScrewUnit.dir_for(:public)
79 | public_path.should == current_slice_root / 'public'
80 | [:stylesheet, :javascript, :image].each do |type|
81 | MerbScrewUnit.dir_for(type).should == public_path / "#{type}s"
82 | end
83 | end
84 |
85 | it "should have a app_dir_for method" do
86 | root_path = MerbScrewUnit.app_dir_for(:root)
87 | root_path.should == Merb.root / 'slices' / 'merb_screw_unit'
88 | app_path = MerbScrewUnit.app_dir_for(:application)
89 | app_path.should == root_path / 'app'
90 | [:view, :model, :controller, :helper, :mailer, :part].each do |type|
91 | MerbScrewUnit.app_dir_for(type).should == app_path / "#{type}s"
92 | end
93 | public_path = MerbScrewUnit.app_dir_for(:public)
94 | public_path.should == Merb.dir_for(:public) / 'slices' / 'merb_screw_unit'
95 | [:stylesheet, :javascript, :image].each do |type|
96 | MerbScrewUnit.app_dir_for(type).should == public_path / "#{type}s"
97 | end
98 | end
99 |
100 | it "should have a public_dir_for method" do
101 | public_path = MerbScrewUnit.public_dir_for(:public)
102 | public_path.should == '/slices' / 'merb_screw_unit'
103 | [:stylesheet, :javascript, :image].each do |type|
104 | MerbScrewUnit.public_dir_for(type).should == public_path / "#{type}s"
105 | end
106 | end
107 |
108 | it "should have a public_path_for method" do
109 | public_path = MerbScrewUnit.public_dir_for(:public)
110 | MerbScrewUnit.public_path_for("path", "to", "file").should == public_path / "path" / "to" / "file"
111 | [:stylesheet, :javascript, :image].each do |type|
112 | MerbScrewUnit.public_path_for(type, "path", "to", "file").should == public_path / "#{type}s" / "path" / "to" / "file"
113 | end
114 | end
115 |
116 | it "should have a app_path_for method" do
117 | MerbScrewUnit.app_path_for("path", "to", "file").should == MerbScrewUnit.app_dir_for(:root) / "path" / "to" / "file"
118 | MerbScrewUnit.app_path_for(:controller, "path", "to", "file").should == MerbScrewUnit.app_dir_for(:controller) / "path" / "to" / "file"
119 | end
120 |
121 | it "should have a slice_path_for method" do
122 | MerbScrewUnit.slice_path_for("path", "to", "file").should == MerbScrewUnit.dir_for(:root) / "path" / "to" / "file"
123 | MerbScrewUnit.slice_path_for(:controller, "path", "to", "file").should == MerbScrewUnit.dir_for(:controller) / "path" / "to" / "file"
124 | end
125 |
126 | it "should keep a list of path component types to use when copying files" do
127 | (MerbScrewUnit.mirrored_components & MerbScrewUnit.slice_paths.keys).length.should == MerbScrewUnit.mirrored_components.length
128 | end
129 |
130 | end
--------------------------------------------------------------------------------
/merb_screw_unit/readme.markdown:
--------------------------------------------------------------------------------
1 | # MerbScrewUnit
2 |
3 | A slice for the Merb framework.
4 |
5 | * * *
6 |
7 | merb_screw_unit
8 | |-- LICENSE
9 | |-- README
10 | |-- Rakefile [1]
11 | |-- TODO
12 | |-- app [2]
13 | | |-- controllers
14 | | | |-- application.rb
15 | | | `-- main.rb
16 | | |-- helpers
17 | | | `-- application_helper.rb
18 | | `-- views
19 | | |-- layout
20 | | | `-- merb_screw_unit.html.erb [3]
21 | | `-- main
22 | | `-- index.html.erb
23 | |-- lib
24 | | |-- merb_screw_unit
25 | | | |-- merbtasks.rb [4]
26 | | | `-- slicetasks.rb [5]
27 | | `-- merb_screw_unit.rb [6]
28 | |-- log
29 | | `-- merb_test.log
30 | |-- public [7]
31 | | |-- javascripts
32 | | | `-- master.js
33 | | `-- stylesheets
34 | | `-- master.css
35 | |-- spec [8]
36 | | |-- merb_screw_unit_spec.rb
37 | | |-- controllers
38 | | | `-- main_spec.rb
39 | | `-- spec_helper.rb
40 | `-- stubs [9]
41 | `-- app
42 | `-- controllers
43 | |-- application.rb
44 | `-- main.rb
45 |
46 |
47 | 1. Rake tasks to package/install the gem - edit this to modify the manifest.
48 | 2. The slice application: controllers, models, helpers, views.
49 | 3. The default layout, as specified in Merb::Slices::config[:merb_screw_unit][:layout]
50 | change this to :application to use the app's layout.
51 | 4. Standard rake tasks available to your application.
52 | 5. Your custom application rake tasks.
53 | 6. The main slice file - contains all slice setup logic/config.
54 | 7. Public assets you (optionally) install using rake slices:merb\_screw\_unit:install
55 | 8. Specs for basis slice behaviour - you usually adapt these for your slice.
56 | 9. Stubs of classes/views/files for the end-user to override - usually these
57 | mimic the files in app/ and/or public/; use rake slices:merb\_screw\_unit:stubs to
58 | get started with the override stubs. Also, slices:merb\_screw\_unit:patch will
59 | copy over views to override in addition to the files found in /stubs.
60 |
61 |
62 | To see all available tasks for MerbScrewUnit run:
63 |
64 | rake -T slices:merb_screw_unit
65 |
66 | * * *
67 |
68 | ## Instructions for installation:
69 |
70 | file: config/init.rb
71 |
72 | ### add the slice as a regular dependency
73 |
74 |
75 | dependency 'merb_screw_unit'
76 |
77 |
78 | ### if needed, configure which slices to load and in which order
79 |
80 | Merb::Plugins.config[:merb_slices] = { :queue => ["MerbScrewUnit", ...] }
81 |
82 | ### optionally configure the plugins in a before\_app\_loads callback
83 |
84 | Merb::BootLoader.before_app_loads do
85 |
86 | Merb::Slices::config[:merb_screw_unit][:option] = value
87 |
88 | end
89 |
90 | file: config/router.rb
91 |
92 | ### example: /merb\_screw\_unit/:controller/:action/:id
93 |
94 | r.add_slice(:MerbScrewUnit)
95 |
96 | ### example: /foo/:controller/:action/:id
97 |
98 | r.add_slice(:MerbScrewUnit, 'foo') # same as :path => 'foo'
99 |
100 | ### example: /:lang/:controller/:action/:id (with :a param set)
101 |
102 | r.add_slice(:MerbScrewUnit, :path => ':lang', :params => { :a => 'b' })
103 |
104 | ### example: /:controller/:action/:id
105 |
106 | r.slice(:MerbScrewUnit)
107 |
108 | Normally you should also run the following rake task:
109 |
110 | rake slices:merb_screw_unit:install
111 |
112 | * * *
113 |
114 | ## You can put your application-level overrides in:
115 |
116 | host-app/slices/merb\_screw\_unit/app - controllers, models, views ...
117 |
118 | ### Templates are located in this order:
119 |
120 | 1. host-app/slices/merb\_screw\_unit/app/views/*
121 | 2. gems/merb\_screw\_unit/app/views/*
122 | 3. host-app/app/views/*
123 |
124 | You can use the host application's layout by configuring the
125 | merb\_screw\_unit slice in a before\_app\_loads block:
126 |
127 | Merb::Slices.config[:merb_screw_unit] = { :layout => :application }
128 |
129 | By default :merb\_screw\_unit is used. If you need to override
130 | stylesheets or javascripts, just specify your own files in your layout
131 | instead/in addition to the ones supplied (if any) in
132 | host-app/public/slices/merb\_screw\_unit.
133 |
134 | In any case don't edit those files directly as they may be clobbered any time
135 |
136 | rake merb_screw_unit:install is run.
137 |
138 | * * *
139 |
140 | ## About Slices
141 |
142 | Merb-Slices is a Merb plugin for using and creating application 'slices' which
143 | help you modularize your application. Usually these are reuseable extractions
144 | from your main app. In effect, a Slice is just like a regular Merb MVC
145 | application, both in functionality as well as in structure.
146 |
147 | When you generate a Slice stub structure, a module is setup to serve as a
148 | namespace for your controller, models, helpers etc. This ensures maximum
149 | encapsulation. You could say a Slice is a mixture between a Merb plugin (a
150 | Gem) and a Merb application, reaping the benefits of both.
151 |
152 | A host application can 'mount' a Slice inside the router, which means you have
153 | full over control how it integrates. By default a Slice's routes are prefixed
154 | by its name (a router :namespace), but you can easily provide your own prefix
155 | or leave it out, mounting it at the root of your url-schema. You can even
156 | mount a Slice multiple times and give extra parameters to customize an
157 | instance's behaviour.
158 |
159 | A Slice's Application controller uses controller_for_slice to setup slice
160 | specific behaviour, which mainly affects cascaded view handling. Additionaly,
161 | this method is available to any kind of controller, so it can be used for
162 | Merb Mailer too for example.
163 |
164 | There are many ways which let you customize a Slice's functionality and
165 | appearance without ever touching the Gem-level code itself. It's not only easy
166 | to add template/layout overrides, you can also add/modify controllers, models
167 | and other runtime code from within the host application.
168 |
169 | To create your own Slice run this (somewhere outside of your merb app):
170 |
171 | $ merb-gen slice
--------------------------------------------------------------------------------
/merb_screw_unit/README:
--------------------------------------------------------------------------------
1 | MerbScrewUnit
2 | =============
3 |
4 | A slice for the Merb framework.
5 |
6 | ------------------------------------------------------------------------------
7 |
8 | merb_screw_unit
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 | | | `-- merb_screw_unit.html.erb [3]
22 | | `-- main
23 | | `-- index.html.erb
24 | |-- lib
25 | | |-- merb_screw_unit
26 | | | |-- merbtasks.rb [4]
27 | | | `-- slicetasks.rb [5]
28 | | `-- merb_screw_unit.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 | | |-- merb_screw_unit_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[:merb_screw_unit][: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:merb_screw_unit: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:merb_screw_unit:stubs to
59 | get started with the override stubs. Also, slices:merb_screw_unit: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 MerbScrewUnit run:
64 |
65 | rake -T slices:merb_screw_unit
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 'merb_screw_unit'
76 |
77 | # if needed, configure which slices to load and in which order
78 |
79 | Merb::Plugins.config[:merb_slices] = { :queue => ["MerbScrewUnit", ...] }
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[:merb_screw_unit][:option] = value
86 |
87 | end
88 |
89 | file: config/router.rb
90 |
91 | # example: /merb_screw_unit/:controller/:action/:id
92 |
93 | r.add_slice(:MerbScrewUnit)
94 |
95 | # example: /foo/:controller/:action/:id
96 |
97 | r.add_slice(:MerbScrewUnit, 'foo') # same as :path => 'foo'
98 |
99 | # example: /:lang/:controller/:action/:id (with :a param set)
100 |
101 | r.add_slice(:MerbScrewUnit, :path => ':lang', :params => { :a => 'b' })
102 |
103 | # example: /:controller/:action/:id
104 |
105 | r.slice(:MerbScrewUnit)
106 |
107 | Normally you should also run the following rake task:
108 |
109 | rake slices:merb_screw_unit:install
110 |
111 | ------------------------------------------------------------------------------
112 |
113 | You can put your application-level overrides in:
114 |
115 | host-app/slices/merb_screw_unit/app - controllers, models, views ...
116 |
117 | Templates are located in this order:
118 |
119 | 1. host-app/slices/merb_screw_unit/app/views/*
120 | 2. gems/merb_screw_unit/app/views/*
121 | 3. host-app/app/views/*
122 |
123 | You can use the host application's layout by configuring the
124 | merb_screw_unit slice in a before_app_loads block:
125 |
126 | Merb::Slices.config[:merb_screw_unit] = { :layout => :application }
127 |
128 | By default :merb_screw_unit 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/merb_screw_unit.
132 |
133 | In any case don't edit those files directly as they may be clobbered any time
134 | rake merb_screw_unit: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
--------------------------------------------------------------------------------
/merb_screw_unit/lib/merb_screw_unit/merbtasks.rb:
--------------------------------------------------------------------------------
1 | namespace :slices do
2 | namespace :merb_screw_unit do
3 |
4 | desc "Install MerbScrewUnit"
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 | MerbScrewUnit.mirrored_components.each do |type|
15 | if File.directory?(MerbScrewUnit.dir_for(type))
16 | if !File.directory?(dst_path = MerbScrewUnit.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 MerbScrewUnit - resolves any collisions"
28 | copied, preserved = MerbScrewUnit.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 MerbScrewUnit - resolves any collisions"
40 | copied, preserved = MerbScrewUnit.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 MerbScrewUnit into your app (only merb_screw_unit/app)"
51 | task :freeze => [ "freeze:app" ]
52 |
53 | namespace :freeze do
54 |
55 | desc "Freezes MerbScrewUnit by installing the gem into application/gems using merb-freezer"
56 | task :gem do
57 | begin
58 | Object.const_get(:Freezer).freeze(ENV["GEM"] || "merb_screw_unit", ENV["UPDATE"], ENV["MODE"] || 'rubygems')
59 | rescue NameError
60 | puts "! dependency 'merb-freezer' missing"
61 | end
62 | end
63 |
64 | desc "Freezes MerbScrewUnit by copying all files from merb_screw_unit/app to your application"
65 | task :app do
66 | puts "Copying all merb_screw_unit/app files to your application - resolves any collisions"
67 | copied, preserved = MerbScrewUnit.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 = MerbScrewUnit.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 = MerbScrewUnit.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 MerbScrewUnit as a gem and copies over merb_screw_unit/app"
92 | task :app_with_gem => [:gem, :app]
93 |
94 | desc "Freezes MerbScrewUnit by unpacking all files into your application"
95 | task :unpack do
96 | puts "Unpacking MerbScrewUnit files to your application - resolves any collisions"
97 | copied, preserved = MerbScrewUnit.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 MerbScrewUnit 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
--------------------------------------------------------------------------------
/merb_screw_unit/public/javascripts/livequery.jquery.js:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2007 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
2 | * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
3 | * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
4 | *
5 | * Version: @VERSION
6 | * Requires jQuery 1.1.3+
7 | * Docs: http://docs.jquery.com/Plugins/livequery
8 | */
9 |
10 | (function($) {
11 |
12 | $.extend($.fn, {
13 | livequery: function(type, fn, fn2) {
14 | var self = this, q;
15 |
16 | // Handle different call patterns
17 | if ($.isFunction(type))
18 | fn2 = fn, fn = type, type = undefined;
19 |
20 | // See if Live Query already exists
21 | $.each( $.livequery.queries, function(i, query) {
22 | if ( self.selector == query.selector && self.context == query.context &&
23 | type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
24 | // Found the query, exit the each loop
25 | return (q = query) && false;
26 | });
27 |
28 | // Create new Live Query if it wasn't found
29 | q = q || new $.livequery(this.selector, this.context, type, fn, fn2);
30 |
31 | // Make sure it is running
32 | q.stopped = false;
33 |
34 | // Run it
35 | $.livequery.run( q.id );
36 |
37 | // Contnue the chain
38 | return this;
39 | },
40 |
41 | expire: function(type, fn, fn2) {
42 | var self = this;
43 |
44 | // Handle different call patterns
45 | if ($.isFunction(type))
46 | fn2 = fn, fn = type, type = undefined;
47 |
48 | // Find the Live Query based on arguments and stop it
49 | $.each( $.livequery.queries, function(i, query) {
50 | if ( self.selector == query.selector && self.context == query.context &&
51 | (!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
52 | $.livequery.stop(query.id);
53 | });
54 |
55 | // Continue the chain
56 | return this;
57 | }
58 | });
59 |
60 | $.livequery = function(selector, context, type, fn, fn2) {
61 | this.selector = selector;
62 | this.context = context || document;
63 | this.type = type;
64 | this.fn = fn;
65 | this.fn2 = fn2;
66 | this.elements = [];
67 | this.stopped = false;
68 |
69 | // The id is the index of the Live Query in $.livequery.queries
70 | this.id = $.livequery.queries.push(this)-1;
71 |
72 | // Mark the functions for matching later on
73 | fn.$lqguid = fn.$lqguid || $.livequery.guid++;
74 | if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;
75 |
76 | // Return the Live Query
77 | return this;
78 | };
79 |
80 | $.livequery.prototype = {
81 | stop: function() {
82 | var query = this;
83 |
84 | if ( this.type )
85 | // Unbind all bound events
86 | this.elements.unbind(this.type, this.fn);
87 | else if (this.fn2)
88 | // Call the second function for all matched elements
89 | this.elements.each(function(i, el) {
90 | query.fn2.apply(el);
91 | });
92 |
93 | // Clear out matched elements
94 | this.elements = [];
95 |
96 | // Stop the Live Query from running until restarted
97 | this.stopped = true;
98 | },
99 |
100 | run: function() {
101 | // Short-circuit if stopped
102 | if ( this.stopped ) return;
103 | var query = this;
104 |
105 | var oEls = this.elements,
106 | els = $(this.selector, this.context),
107 | nEls = els.not(oEls);
108 |
109 | // Set elements to the latest set of matched elements
110 | this.elements = els;
111 |
112 | if (this.type) {
113 | // Bind events to newly matched elements
114 | nEls.bind(this.type, this.fn);
115 |
116 | // Unbind events to elements no longer matched
117 | if (oEls.length > 0)
118 | $.each(oEls, function(i, el) {
119 | if ( $.inArray(el, els) < 0 )
120 | $.event.remove(el, query.type, query.fn);
121 | });
122 | }
123 | else {
124 | // Call the first function for newly matched elements
125 | nEls.each(function() {
126 | query.fn.apply(this);
127 | });
128 |
129 | // Call the second function for elements no longer matched
130 | if ( this.fn2 && oEls.length > 0 )
131 | $.each(oEls, function(i, el) {
132 | if ( $.inArray(el, els) < 0 )
133 | query.fn2.apply(el);
134 | });
135 | }
136 | }
137 | };
138 |
139 | $.extend($.livequery, {
140 | guid: 0,
141 | queries: [],
142 | queue: [],
143 | running: false,
144 | timeout: null,
145 |
146 | checkQueue: function() {
147 | if ( $.livequery.running && $.livequery.queue.length ) {
148 | var length = $.livequery.queue.length;
149 | // Run each Live Query currently in the queue
150 | while ( length-- )
151 | $.livequery.queries[ $.livequery.queue.shift() ].run();
152 | }
153 | },
154 |
155 | pause: function() {
156 | // Don't run anymore Live Queries until restarted
157 | $.livequery.running = false;
158 | },
159 |
160 | play: function() {
161 | // Restart Live Queries
162 | $.livequery.running = true;
163 | // Request a run of the Live Queries
164 | $.livequery.run();
165 | },
166 |
167 | registerPlugin: function() {
168 | $.each( arguments, function(i,n) {
169 | // Short-circuit if the method doesn't exist
170 | if (!$.fn[n]) return;
171 |
172 | // Save a reference to the original method
173 | var old = $.fn[n];
174 |
175 | // Create a new method
176 | $.fn[n] = function() {
177 | // Call the original method
178 | var r = old.apply(this, arguments);
179 |
180 | // Request a run of the Live Queries
181 | $.livequery.run();
182 |
183 | // Return the original methods result
184 | return r;
185 | }
186 | });
187 | },
188 |
189 | run: function(id) {
190 | if (id != undefined) {
191 | // Put the particular Live Query in the queue if it doesn't already exist
192 | if ( $.inArray(id, $.livequery.queue) < 0 )
193 | $.livequery.queue.push( id );
194 | }
195 | else
196 | // Put each Live Query in the queue if it doesn't already exist
197 | $.each( $.livequery.queries, function(id) {
198 | if ( $.inArray(id, $.livequery.queue) < 0 )
199 | $.livequery.queue.push( id );
200 | });
201 |
202 | // Clear timeout if it already exists
203 | if ($.livequery.timeout) clearTimeout($.livequery.timeout);
204 | // Create a timeout to check the queue and actually run the Live Queries
205 | $.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
206 | },
207 |
208 | stop: function(id) {
209 | if (id != undefined)
210 | // Stop are particular Live Query
211 | $.livequery.queries[ id ].stop();
212 | else
213 | // Stop all Live Queries
214 | $.each( $.livequery.queries, function(id) {
215 | $.livequery.queries[ id ].stop();
216 | });
217 | }
218 | });
219 |
220 | // Register core DOM manipulation methods
221 | $.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove');
222 |
223 | // Run Live Queries when the Document is ready
224 | $(function() { $.livequery.play(); });
225 |
226 |
227 | // Save a reference to the original init method
228 | var init = $.prototype.init;
229 |
230 | // Create a new init method that exposes two new properties: selector and context
231 | $.prototype.init = function(a,c) {
232 | // Call the original init and save the result
233 | var r = init.apply(this, arguments);
234 |
235 | // Copy over properties if they exist already
236 | if (a && a.selector)
237 | r.context = a.context, r.selector = a.selector;
238 |
239 | // Set properties
240 | if ( typeof a == 'string' )
241 | r.context = c || document, r.selector = a;
242 |
243 | // Return the result
244 | return r;
245 | };
246 |
247 | // Give the init function the jQuery prototype for later instantiation (needed after Rev 4091)
248 | $.prototype.init.prototype = $.prototype;
249 |
250 | })(jQuery);
--------------------------------------------------------------------------------