muggle 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +7 -0
- data/bin/muggle +8 -0
- data/lib/muggle.rb +13 -0
- data/lib/muggle/application.rb +26 -0
- data/lib/muggle/assets.rb +16 -0
- data/lib/muggle/assets/configuration.rb +15 -0
- data/lib/muggle/assets/middleware.rb +32 -0
- data/lib/muggle/cli/create.rb +46 -0
- data/lib/muggle/cli/templates/Gemfile.erb +5 -0
- data/lib/muggle/cli/templates/config.ru.erb +10 -0
- data/lib/muggle/cli/templates/config/application.rb.erb +27 -0
- data/lib/muggle/cli/templates/config/routes.rb.erb +2 -0
- data/lib/muggle/controller.rb +36 -0
- data/lib/muggle/routing/route.rb +17 -0
- data/lib/muggle/routing/route_collection.rb +29 -0
- data/lib/muggle/routing/route_not_found_exception.rb +5 -0
- data/lib/muggle/version.rb +3 -0
- data/muggle.gemspec +31 -0
- data/spec/hogger/assets/configuration_spec.rb +16 -0
- data/spec/hogger/assets/middleware_spec.rb +49 -0
- data/spec/muggle/cli/create_spec.rb +48 -0
- data/spec/muggle/controller_spec.rb +49 -0
- data/spec/muggle/routing/route_collection_spec.rb +45 -0
- data/spec/muggle/routing/route_spec.rb +22 -0
- data/spec/spec_helper.rb +12 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1c3e777a1ed8ab7b2400b044b986c626ed96ee3
|
4
|
+
data.tar.gz: c12f29bf52d7b0a5a82b261d27077aab6bb7b919
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 791a418064d3265814b32b3441bd0b529998b2ab463b93cd4d87bc83c8d5e265df04b88bac56caf2cdc5da7e4b4fc49b6fa1e8bbee4889c8fa4aaf1a90d68572
|
7
|
+
data.tar.gz: 4903703aff9e26968f2da941a0e51c002080cb8368074fc68086ba650f89fd12fd6ef55c30555a7f567559a2393d2c0254038117584d0be21de7ae959dc3d45e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Crowd Interactive
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/crowdint/muggle.png?branch=master)](https://travis-ci.org/crowdint/muggle)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/crowdint/muggle/badge.png?branch=master)](https://coveralls.io/r/crowdint/muggle)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/crowdint/muggle.png)](https://codeclimate.com/github/crowdint/muggle)
|
4
|
+
|
5
|
+
# Muggle
|
6
|
+
|
7
|
+
VERY lightweight web application framework for Ruby. There's no magic in Muggle.
|
8
|
+
|
9
|
+
## Why?
|
10
|
+
|
11
|
+
To teach new programmers the basic of MVC without necesarily exposing them to a
|
12
|
+
big Framework like Rails.
|
13
|
+
|
14
|
+
We don't need Ruby on Rails Engineers in the world, we need Ruby Engineers.
|
15
|
+
|
16
|
+
While Ruby on Rails allows you to easily forget about the entrails of a web app,
|
17
|
+
this Framework is about the opposite thing.
|
18
|
+
|
19
|
+
That means, no Convention over Configuration, no magic behind paths, routes, models
|
20
|
+
or any sugar Rails add to your life.
|
21
|
+
|
22
|
+
## Current Status
|
23
|
+
|
24
|
+
You can create an app skeleton running the following command:
|
25
|
+
|
26
|
+
muggle NewApp
|
27
|
+
|
28
|
+
Notice that you need to pass the app name as a Ruby class name.
|
29
|
+
|
30
|
+
### Sample App
|
31
|
+
|
32
|
+
To use the sample app go to the *sample-app* directory and run:
|
33
|
+
|
34
|
+
rackup
|
35
|
+
|
36
|
+
This app has one controller: *HelloController* and is routed to the */hello* path.
|
37
|
+
|
38
|
+
Use your browser to go to *http://127.0.0.1:9292/hello* and you should see the classic
|
39
|
+
Hello World message.
|
40
|
+
|
41
|
+
The action accepts the name parameter, so, if you go to *http://127.0.0.1:9292/hello?name=John*
|
42
|
+
you will see *Hello World John*.
|
43
|
+
|
44
|
+
The app file structure is similar to Rails, figure out what the files do.
|
45
|
+
|
46
|
+
# About the Author
|
47
|
+
|
48
|
+
[Crowd Interactive](http://www.crowdint.com) is a leading Ruby and Rails
|
49
|
+
consultancy firm based in Mexico currently doing business with startups in
|
50
|
+
the United States. We specialize in building and growing your existing
|
51
|
+
development team, by adding engineers onsite or offsite. We pick our clients
|
52
|
+
carefully, as we only work with companies we, believe in. Find out more about
|
53
|
+
us on our [website](http://www.crowdint.com).
|
data/Rakefile
ADDED
data/bin/muggle
ADDED
data/lib/muggle.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'haml'
|
3
|
+
require 'sprockets'
|
4
|
+
|
5
|
+
require 'muggle/version'
|
6
|
+
require 'muggle/application'
|
7
|
+
require 'muggle/controller'
|
8
|
+
require 'muggle/routing/route_collection'
|
9
|
+
require 'muggle/routing/route'
|
10
|
+
require 'muggle/routing/route_not_found_exception'
|
11
|
+
require 'muggle/assets'
|
12
|
+
|
13
|
+
module Muggle ; end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Muggle
|
2
|
+
class Application
|
3
|
+
class << self
|
4
|
+
attr_accessor :root_path
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.routes
|
8
|
+
@@routes ||= Muggle::Routing::RouteCollection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.routes=(value)
|
12
|
+
@@routes = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.setup!
|
16
|
+
Muggle::Application.root_path = ENV['HOGGER_ROOT']
|
17
|
+
load "config/routes.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
body = self.class.routes.dispatch(env)
|
22
|
+
headers = { "Content-Length" => body.length.to_s }
|
23
|
+
[200, headers, [body]]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hogger
|
2
|
+
module Assets
|
3
|
+
extend self
|
4
|
+
|
5
|
+
require 'muggle/assets/configuration'
|
6
|
+
require 'muggle/assets/middleware'
|
7
|
+
|
8
|
+
def self.configure &block
|
9
|
+
block.call(config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@@config ||= Configuration.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Hogger
|
2
|
+
module Assets
|
3
|
+
class Middleware
|
4
|
+
attr_reader :environment, :app
|
5
|
+
|
6
|
+
def initialize app
|
7
|
+
@app = app
|
8
|
+
@environment = create_assets_env
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
path = env['PATH_INFO']
|
13
|
+
if path.match /\/assets/
|
14
|
+
env['PATH_INFO'].sub!('/assets', '')
|
15
|
+
@environment.call(env)
|
16
|
+
else
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def create_assets_env
|
24
|
+
env = Sprockets::Environment.new
|
25
|
+
Assets.config.load_paths.each do |path|
|
26
|
+
env.append_path path
|
27
|
+
end
|
28
|
+
env
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
module Muggle
|
4
|
+
module CLI
|
5
|
+
class Create
|
6
|
+
attr_accessor :app_name
|
7
|
+
attr_accessor :root_path
|
8
|
+
|
9
|
+
FOLDERS = %w(app app/controllers app/views config app/assets app/assets/javascripts app/assets/stylesheets)
|
10
|
+
FILES = %w(config.ru config/application.rb config/routes.rb Gemfile)
|
11
|
+
|
12
|
+
def initialize(app_name)
|
13
|
+
self.app_name = app_name
|
14
|
+
self.root_path = "."
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_app_folder
|
18
|
+
app_folder = File.join(self.root_path, app_name)
|
19
|
+
Dir.mkdir app_folder unless Dir.exist?(app_folder)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_app_folder_structure
|
23
|
+
create_app_folder
|
24
|
+
FOLDERS.each do |f|
|
25
|
+
folder = File.join(self.root_path, app_name, f)
|
26
|
+
Dir.mkdir folder unless Dir.exist?(folder)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_files
|
31
|
+
create_app_folder_structure
|
32
|
+
FILES.each do |f|
|
33
|
+
template = File.new(template_path(f))
|
34
|
+
app_name = self.app_name
|
35
|
+
file = File.open(File.join(self.root_path, self.app_name, f), "w")
|
36
|
+
puts "Creating #{file.path}"
|
37
|
+
file.write ERB.new(template.read).result(binding)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def template_path(template)
|
42
|
+
File.join(File.expand_path("../", __FILE__), "templates", "#{template}.erb")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "bundler"
|
2
|
+
|
3
|
+
Bundler.require
|
4
|
+
|
5
|
+
#
|
6
|
+
# Load all controller files
|
7
|
+
#
|
8
|
+
Dir[File.join(File.expand_path("../../app/controllers", __FILE__), "*.rb")].each { |f| load f }
|
9
|
+
|
10
|
+
#
|
11
|
+
# Define the application
|
12
|
+
#
|
13
|
+
module <%= app_name %>
|
14
|
+
class Application < Muggle::Application ; end
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Setup assets
|
19
|
+
#
|
20
|
+
|
21
|
+
Hogger::Assets.configure do |config|
|
22
|
+
config.append_path 'app/assets/javascripts'
|
23
|
+
config.append_path 'app/assets/stylesheets'
|
24
|
+
end
|
25
|
+
|
26
|
+
<%= app_name %>::Application.setup!
|
27
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Muggle
|
2
|
+
class Controller
|
3
|
+
attr_accessor :params
|
4
|
+
attr_accessor :env
|
5
|
+
|
6
|
+
def initialize(env)
|
7
|
+
self.env = env
|
8
|
+
parse_parameters
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_parameters
|
12
|
+
self.params = Rack::Utils.parse_nested_query(env["QUERY_STRING"])
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(view_path, locals = {})
|
16
|
+
template = read_template(view_path)
|
17
|
+
Haml::Engine.new(template).render(Object.new, locals)
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_with_layout(view_path, layout_name, locals = {})
|
21
|
+
layout = read_layout(layout_name)
|
22
|
+
Haml::Engine.new(layout).render(Object.new, locals) do
|
23
|
+
render(view_path, locals)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
def read_template(view_path)
|
29
|
+
File.new(view_path).read
|
30
|
+
end
|
31
|
+
|
32
|
+
def read_layout(layout_name)
|
33
|
+
File.new(layout_name).read
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Muggle
|
2
|
+
module Routing
|
3
|
+
class Route
|
4
|
+
attr_accessor :path, :controller, :action
|
5
|
+
|
6
|
+
def initialize(path, options)
|
7
|
+
self.path = path
|
8
|
+
self.controller = options[:controller]
|
9
|
+
self.action = options[:action]
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?(path)
|
13
|
+
self.path == path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Muggle
|
2
|
+
module Routing
|
3
|
+
class RouteCollection
|
4
|
+
attr_accessor :routes
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.routes = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def draw(&block)
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
def match(uri, options)
|
15
|
+
self.routes << Route.new(uri, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def dispatch(env)
|
19
|
+
path = env["REQUEST_PATH"]
|
20
|
+
route = self.routes.select { |r| r.matches?(path) }.first
|
21
|
+
if route
|
22
|
+
route.controller.new(env).send(route.action)
|
23
|
+
else
|
24
|
+
raise RouteNotFoundException, "Route not found: #{path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/muggle.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'muggle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "muggle"
|
8
|
+
spec.version = Muggle::VERSION
|
9
|
+
spec.authors = ["David Padilla"]
|
10
|
+
spec.email = ["david@crowdint.com"]
|
11
|
+
spec.description = %q{VERY simple framework for Web Applications}
|
12
|
+
spec.summary = %q{VERY simple framework for Web Applications}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.files.reject! { |fn| fn =~ /^sample-app/ }
|
18
|
+
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "rack"
|
24
|
+
spec.add_dependency "haml"
|
25
|
+
spec.add_dependency "sprockets"
|
26
|
+
|
27
|
+
spec.add_development_dependency "coveralls"
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hogger::Assets::Configuration do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'initialize @load_paths with and empty array' do
|
6
|
+
expect(subject.load_paths).to be_empty
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '@append_path' do
|
11
|
+
it 'append a path to the load path' do
|
12
|
+
expect{subject.append_path 'foo/path'}.to change{subject.load_paths}.
|
13
|
+
from([]).to(['foo/path'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hogger::Assets::Middleware do
|
4
|
+
let(:app) { mock(call: mock) }
|
5
|
+
let(:env) { mock }
|
6
|
+
let(:app_env) { Hash.new }
|
7
|
+
|
8
|
+
subject { Hogger::Assets::Middleware.new(app) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Hogger::Assets.config.stub load_paths: ['load/path']
|
12
|
+
Sprockets::Environment.should_receive(:new).and_return env
|
13
|
+
env.should_receive(:append_path).with('load/path')
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#initialize' do
|
17
|
+
it 'sets app' do
|
18
|
+
expect(subject.app).to_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'create an sprockets env' do
|
22
|
+
expect(subject.environment).to eq env
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#call' do
|
27
|
+
context 'When request_path is "/assets"' do
|
28
|
+
before do
|
29
|
+
app_env['PATH_INFO'] = '/assets'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should call the assets env' do
|
33
|
+
env.should_receive(:call)
|
34
|
+
subject.call(app_env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'When request_path is not "/assets"' do
|
39
|
+
before do
|
40
|
+
app_env['PATH_INFO'] = '/'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should call the the app env' do
|
44
|
+
app.should_receive(:call)
|
45
|
+
subject.call(app_env)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fileutils"
|
3
|
+
require "muggle/cli/create"
|
4
|
+
|
5
|
+
describe Muggle::CLI::Create do
|
6
|
+
let(:root_path) { "tmp" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
FileUtils.rm_r root_path if Dir.exist? root_path
|
10
|
+
Dir.mkdir root_path
|
11
|
+
subject.root_path = root_path
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { Muggle::CLI::Create.new "MuggleApp" }
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it "sets the app_name" do
|
18
|
+
subject.app_name.should eq subject.app_name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#create_app_folder" do
|
23
|
+
it "creates the app folder" do
|
24
|
+
subject.create_app_folder
|
25
|
+
Dir.exist?(File.join(root_path, subject.app_name)).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#create_app_folder_structure" do
|
30
|
+
it "creates the folder structure" do
|
31
|
+
subject.create_app_folder
|
32
|
+
subject.create_app_folder_structure
|
33
|
+
Muggle::CLI::Create::FOLDERS.each do |f|
|
34
|
+
Dir.exist?(File.join(root_path, subject.app_name, f)).should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#create_files" do
|
40
|
+
it "creates the files" do
|
41
|
+
subject.create_app_folder_structure
|
42
|
+
subject.create_files
|
43
|
+
Muggle::CLI::Create::FILES.each do |f|
|
44
|
+
File.exist?(File.join(subject.root_path, subject.app_name, f)).should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Muggle::Controller do
|
4
|
+
let(:env) do
|
5
|
+
{ "QUERY_STRING"=>"name=john&last_name=doe" }
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:subject) do
|
9
|
+
Muggle::Controller.new env
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "sets env" do
|
14
|
+
subject.env.should be env
|
15
|
+
end
|
16
|
+
|
17
|
+
it "calls parse_parameters" do
|
18
|
+
Muggle::Controller.any_instance.should_receive(:parse_parameters)
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#parse_parameters" do
|
24
|
+
it "sets the parameters as a hash on params" do
|
25
|
+
subject.params.should eq({ "name" => "john", "last_name" => "doe" })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#render" do
|
30
|
+
it "reads the template and parses it with HAML" do
|
31
|
+
subject.should_receive(:read_template).with("test.html.haml").
|
32
|
+
and_return "%html\n %title=foo"
|
33
|
+
subject.render("test.html.haml", { "foo" => "bar" }).
|
34
|
+
should eq "<html>\n <title>bar</title>\n</html>\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#render_with_layout" do
|
39
|
+
it "renders the template within a layout" do
|
40
|
+
subject.should_receive(:read_layout).with("layout.html.haml").
|
41
|
+
and_return "%html\n %body= yield"
|
42
|
+
subject.should_receive(:read_template).with("test.html.haml").
|
43
|
+
and_return "#test content"
|
44
|
+
|
45
|
+
subject.render_with_layout("test.html.haml", "layout.html.haml").
|
46
|
+
should eq "<html>\n <body><div id='test'>content</div></body>\n</html>\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Muggle::Routing::RouteCollection do
|
4
|
+
let(:controller_class) do
|
5
|
+
Class.new
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:route) do
|
9
|
+
Muggle::Routing::Route.new "/hello", controller: controller_class, action: :new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
subject.routes << route
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#match" do
|
17
|
+
it "creates a Route with specified options" do
|
18
|
+
mocked_route = mock
|
19
|
+
Muggle::Routing::Route.should_receive(:new).
|
20
|
+
with("/new_path", controller: controller_class, action: :create).
|
21
|
+
and_return mocked_route
|
22
|
+
subject.match("/new_path", controller: controller_class, action: :create)
|
23
|
+
subject.routes.should include(mocked_route)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#dispatch" do
|
28
|
+
context "A Route that exists" do
|
29
|
+
it "calls the specified action on the Route controller class" do
|
30
|
+
controller = mock
|
31
|
+
controller_class.should_receive(:new).and_return controller
|
32
|
+
controller.should_receive(:new).and_return("HTML CONTENT")
|
33
|
+
subject.dispatch({ "REQUEST_PATH" => "/hello"}).should eq "HTML CONTENT"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "A route that does not exist" do
|
38
|
+
it "raises a Muggle::RouteNotFoundException" do
|
39
|
+
expect {
|
40
|
+
subject.dispatch("/unknown")
|
41
|
+
}.to raise_error Muggle::Routing::RouteNotFoundException
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Muggle::Routing::Route do
|
4
|
+
let(:controller_class) do
|
5
|
+
Class.new
|
6
|
+
end
|
7
|
+
|
8
|
+
subject do
|
9
|
+
Muggle::Routing::Route.new "/home", controller: controller_class, action: :new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :initialize do
|
13
|
+
specify { subject.path.should eq "/home" }
|
14
|
+
specify { subject.controller.should be controller_class }
|
15
|
+
specify { subject.action.should be :new }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :matches? do
|
19
|
+
specify { subject.matches?("/home").should be_true }
|
20
|
+
specify { subject.matches?("/homer").should be_false }
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
require "muggle"
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
config.order = 'random'
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: muggle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Padilla
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: haml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sprockets
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.13.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.13.0
|
111
|
+
description: VERY simple framework for Web Applications
|
112
|
+
email:
|
113
|
+
- david@crowdint.com
|
114
|
+
executables:
|
115
|
+
- muggle
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .travis.yml
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/muggle
|
127
|
+
- lib/muggle.rb
|
128
|
+
- lib/muggle/application.rb
|
129
|
+
- lib/muggle/assets.rb
|
130
|
+
- lib/muggle/assets/configuration.rb
|
131
|
+
- lib/muggle/assets/middleware.rb
|
132
|
+
- lib/muggle/cli/create.rb
|
133
|
+
- lib/muggle/cli/templates/Gemfile.erb
|
134
|
+
- lib/muggle/cli/templates/config.ru.erb
|
135
|
+
- lib/muggle/cli/templates/config/application.rb.erb
|
136
|
+
- lib/muggle/cli/templates/config/routes.rb.erb
|
137
|
+
- lib/muggle/controller.rb
|
138
|
+
- lib/muggle/routing/route.rb
|
139
|
+
- lib/muggle/routing/route_collection.rb
|
140
|
+
- lib/muggle/routing/route_not_found_exception.rb
|
141
|
+
- lib/muggle/version.rb
|
142
|
+
- muggle.gemspec
|
143
|
+
- spec/hogger/assets/configuration_spec.rb
|
144
|
+
- spec/hogger/assets/middleware_spec.rb
|
145
|
+
- spec/muggle/cli/create_spec.rb
|
146
|
+
- spec/muggle/controller_spec.rb
|
147
|
+
- spec/muggle/routing/route_collection_spec.rb
|
148
|
+
- spec/muggle/routing/route_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
homepage: ''
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - '>'
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: 1.3.1
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.0.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: VERY simple framework for Web Applications
|
174
|
+
test_files:
|
175
|
+
- spec/hogger/assets/configuration_spec.rb
|
176
|
+
- spec/hogger/assets/middleware_spec.rb
|
177
|
+
- spec/muggle/cli/create_spec.rb
|
178
|
+
- spec/muggle/controller_spec.rb
|
179
|
+
- spec/muggle/routing/route_collection_spec.rb
|
180
|
+
- spec/muggle/routing/route_spec.rb
|
181
|
+
- spec/spec_helper.rb
|