hanlon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +27 -0
- data/Rakefile +20 -0
- data/hanlon.gemspec +24 -0
- data/lib/hanlon/engine.rb +24 -0
- data/lib/hanlon/loader.rb +30 -0
- data/lib/hanlon/version.rb +3 -0
- data/lib/hanlon.rb +7 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/engine_spec.rb +17 -0
- data/spec/unit/hanlon_spec.rb +4 -0
- data/spec/unit/loader_spec.rb +33 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hanlon (0.0.1)
|
5
|
+
haml
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
haml (3.1.2)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
haml
|
26
|
+
hanlon!
|
27
|
+
rspec
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
namespace :spec do
|
6
|
+
types = [:unit]
|
7
|
+
|
8
|
+
types.each do |type|
|
9
|
+
desc "Run #{type} specs only"
|
10
|
+
RSpec::Core::RakeTask.new(type) do |spec|
|
11
|
+
spec.pattern = "spec/#{type}/**/*_spec.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run All Specs"
|
16
|
+
task :all => types
|
17
|
+
end
|
18
|
+
|
19
|
+
task :spec => ['spec:all']
|
20
|
+
task :default => :spec
|
data/hanlon.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hanlon/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hanlon"
|
7
|
+
s.version = Hanlon::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['cohitre']
|
10
|
+
s.email = ['i@cohitre.com']
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Define rails helpers with Haml}
|
13
|
+
s.description = %q{Use Haml to generate rails helpers.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "hanlon"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_dependency 'haml'
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Hanlon
|
2
|
+
class Engine
|
3
|
+
def initialize hanlon_text, options={}
|
4
|
+
@haml_engine = Haml::Engine.new hanlon_text, options
|
5
|
+
end
|
6
|
+
|
7
|
+
def module
|
8
|
+
@module ||= process
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
12
|
+
loader = Hanlon::Loader.new
|
13
|
+
@haml_engine.render loader
|
14
|
+
@module = loader.build
|
15
|
+
end
|
16
|
+
|
17
|
+
def evaluate haml
|
18
|
+
klass = Class.new
|
19
|
+
klass.send :include, self.module
|
20
|
+
engine = Haml::Engine.new haml
|
21
|
+
engine.render klass.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Hanlon
|
2
|
+
class Loader
|
3
|
+
def initialize
|
4
|
+
@loaded_methods = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def add_method name, &block
|
8
|
+
@loaded_methods[name] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def hanlon name, &block
|
12
|
+
add_method name do |*helper_args|
|
13
|
+
capture_haml *helper_args, &block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def [] name
|
18
|
+
@loaded_methods[name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
loaded_methods = @loaded_methods
|
23
|
+
Module.new do
|
24
|
+
loaded_methods.each_pair do |key, value|
|
25
|
+
define_method key, value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/hanlon.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.color_enabled = true
|
10
|
+
|
11
|
+
config.filter_run :focus => true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'hanlon'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hanlon::Engine do
|
4
|
+
describe '#process' do
|
5
|
+
it 'should return a module with the defined methods' do
|
6
|
+
engine = Hanlon::Engine.new %q<
|
7
|
+
- hanlon :greeting do |name|
|
8
|
+
%p== hello #{name}.
|
9
|
+
- hanlon :headline do
|
10
|
+
%h1 Headline>
|
11
|
+
|
12
|
+
engine.module.should be_a(Module)
|
13
|
+
engine.evaluate("= greeting 'Carlos'").should == "<p>hello Carlos.</p>\n"
|
14
|
+
engine.evaluate("= headline").should == "<h1>Headline</h1>\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hanlon::Loader do
|
4
|
+
describe '#add_method' do
|
5
|
+
it 'should add a method to the methods hash' do
|
6
|
+
loader = Hanlon::Loader.new
|
7
|
+
loader.add_method :headline do
|
8
|
+
'headline'
|
9
|
+
end
|
10
|
+
loader[:headline].should be_a Proc
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#build' do
|
15
|
+
it 'should return a module with the defined methods' do
|
16
|
+
loader = Hanlon::Loader.new
|
17
|
+
loader.add_method :headline do
|
18
|
+
'headline'
|
19
|
+
end
|
20
|
+
loader.add_method :paragraph do
|
21
|
+
'bogus'
|
22
|
+
end
|
23
|
+
mod = loader.build
|
24
|
+
mod.should be_a Module
|
25
|
+
ModuleHelper = mod
|
26
|
+
class ModuleTester
|
27
|
+
include ModuleHelper
|
28
|
+
end
|
29
|
+
ModuleTester.new.paragraph.should == 'bogus'
|
30
|
+
ModuleTester.new.headline.should == 'headline'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hanlon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- cohitre
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-08-07 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: haml
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Use Haml to generate rails helpers.
|
47
|
+
email:
|
48
|
+
- i@cohitre.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- Rakefile
|
60
|
+
- hanlon.gemspec
|
61
|
+
- lib/hanlon.rb
|
62
|
+
- lib/hanlon/engine.rb
|
63
|
+
- lib/hanlon/loader.rb
|
64
|
+
- lib/hanlon/version.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
- spec/unit/engine_spec.rb
|
67
|
+
- spec/unit/hanlon_spec.rb
|
68
|
+
- spec/unit/loader_spec.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: ""
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: hanlon
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Define rails helpers with Haml
|
101
|
+
test_files:
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/unit/engine_spec.rb
|
104
|
+
- spec/unit/hanlon_spec.rb
|
105
|
+
- spec/unit/loader_spec.rb
|