collin-fold 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile.rb +36 -10
- data/lib/fold/engine.rb +5 -7
- data/lib/fold/fold_factory.rb +14 -2
- data/lib/fold/precompiler.rb +3 -0
- data/lib/fold.rb +3 -0
- data/rspec/fixtures/fold/empty.target.fold +0 -0
- data/rspec/fixtures/fold/fixture.target.fold +0 -0
- data/rspec/fold/engine_spec.rb +9 -16
- data/rspec/fold/fold_factory_spec.rb +14 -1
- data/rspec/fold/precompiler_spec.rb +4 -0
- data/rspec/fold_spec_helper.rb +5 -3
- metadata +4 -4
data/Rakefile.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
__DIR__ = path = File.dirname(__FILE__)
|
2
|
-
|
3
1
|
require 'rubygems'
|
2
|
+
require 'pathname'
|
4
3
|
require 'spec'
|
5
4
|
|
5
|
+
__DIR__ = Pathname.new(__FILE__).dirname
|
6
|
+
|
7
|
+
|
8
|
+
task :default => 'spec:all'
|
9
|
+
|
6
10
|
namespace :spec do
|
7
11
|
task :prepare do
|
8
12
|
|
@@ -18,26 +22,48 @@ namespace :spec do
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
25
|
+
task :cleanup do
|
26
|
+
Dir.glob("**/*.*~")+Dir.glob("**/*~").each{|swap|FileUtils.rm(swap, :force => true)}
|
27
|
+
end
|
28
|
+
|
21
29
|
namespace :gem do
|
22
|
-
task :
|
23
|
-
|
24
|
-
|
30
|
+
task :version do
|
31
|
+
@version = "0.0.6"
|
32
|
+
end
|
33
|
+
|
34
|
+
task :build => :spec do
|
35
|
+
load __DIR__ + "fold.gemspec"
|
36
|
+
Gem::Builder.new(@fold_gemspec).build
|
37
|
+
end
|
38
|
+
|
39
|
+
task :install => :build do
|
40
|
+
cmd = "gem install fold -l"
|
41
|
+
system cmd unless system "sudo #{cmd}"
|
42
|
+
FileUtils.rm(__DIR__ + "fold-#{@version}.gem")
|
43
|
+
end
|
44
|
+
|
45
|
+
task :spec => :version do
|
46
|
+
file = File.new(__DIR__ + "fold.gemspec", 'w+')
|
47
|
+
FileUtils.chmod 0755, __DIR__ + "fold.gemspec"
|
48
|
+
spec = %{
|
25
49
|
Gem::Specification.new do |s|
|
26
50
|
s.name = "fold"
|
27
|
-
s.
|
28
|
-
s.
|
51
|
+
s.date = "2008-07-21"
|
52
|
+
s.version = "#{@version}"
|
53
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
29
54
|
s.has_rdoc = false
|
30
55
|
s.summary = "Toolkit for creating whitespace active mini-languages. Inspired by Haml. Feature light."
|
31
|
-
s.
|
32
|
-
s.author = "Collin Miller"
|
56
|
+
s.authors = ["Collin Miller"]
|
33
57
|
s.email = "collintmiller@gmail.com"
|
34
58
|
s.homepage = "http://github.com/collin/fold"
|
35
|
-
s.require_path = "lib"
|
36
59
|
s.files = %w{#{(%w(README Rakefile.rb) + Dir.glob("{lib,rspec}/**/*")).join(' ')}}
|
37
60
|
|
38
61
|
s.add_dependency "rake"
|
39
62
|
s.add_dependency "rspec"
|
40
63
|
end
|
41
64
|
}
|
65
|
+
|
66
|
+
@fold_gemspec = eval(spec)
|
67
|
+
file.write(spec)
|
42
68
|
end
|
43
69
|
end
|
data/lib/fold/engine.rb
CHANGED
@@ -2,11 +2,6 @@ module Fold
|
|
2
2
|
class Engine
|
3
3
|
def initialize source
|
4
4
|
@source= source
|
5
|
-
prepare_source
|
6
|
-
end
|
7
|
-
|
8
|
-
def prepare_source
|
9
|
-
@prepared_source= true
|
10
5
|
end
|
11
6
|
|
12
7
|
def lines
|
@@ -14,11 +9,14 @@ module Fold
|
|
14
9
|
end
|
15
10
|
|
16
11
|
def render context
|
17
|
-
precompiler.new
|
12
|
+
precompiler = precompiler_class.new
|
13
|
+
precompiler.fold(lines).children.map do |child|
|
14
|
+
child.render(precompiler)
|
15
|
+
end
|
18
16
|
end
|
19
17
|
|
20
18
|
# *** me hard
|
21
|
-
def
|
19
|
+
def precompiler_class
|
22
20
|
@precompiler||= instance_eval "#{self.class.to_s.split(/::/).first}::Precompiler"
|
23
21
|
end
|
24
22
|
end
|
data/lib/fold/fold_factory.rb
CHANGED
@@ -14,12 +14,24 @@ module Fold
|
|
14
14
|
:text => line,
|
15
15
|
:tabs => tabs
|
16
16
|
}
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
# This all happens because I need to access Precompiler attributes
|
19
|
+
# from within AbstractFold render methods
|
20
|
+
# Pretty much needs a nice refactor, but don't have the time.
|
21
|
+
# PS: thx ruby
|
22
|
+
fold = if klass= detect_class(line)
|
19
23
|
klass.new attrs
|
20
24
|
else
|
21
25
|
AbstractFold.new attrs.merge(:tabs => -1)
|
22
26
|
end
|
27
|
+
|
28
|
+
instance_variables.each do |var|
|
29
|
+
fold.instance_variable_set var, instance_variable_get(var)
|
30
|
+
|
31
|
+
fold.metaclass.send :attr_accessor, var.gsub('@', '')
|
32
|
+
end
|
33
|
+
|
34
|
+
fold
|
23
35
|
end
|
24
36
|
|
25
37
|
def detect_class line
|
data/lib/fold/precompiler.rb
CHANGED
data/lib/fold.rb
CHANGED
File without changes
|
File without changes
|
data/rspec/fold/engine_spec.rb
CHANGED
@@ -1,32 +1,25 @@
|
|
1
1
|
require 'rspec/fold_spec_helper'
|
2
2
|
|
3
3
|
describe Fold::Engine do
|
4
|
+
before(:each) do
|
5
|
+
@fixture = Pathname.new(FoldFixtureRoot)
|
6
|
+
@path= @fixture +"fixture.target.fold"
|
7
|
+
@engine= Fold::Engine.new @path.read
|
8
|
+
|
9
|
+
# @empty = @fixture + "empty.target.fold"
|
10
|
+
# @empty_engine = Fold::Engine.new @empty.read
|
11
|
+
end
|
12
|
+
|
4
13
|
it "inherits Module" do
|
5
14
|
Fold::Engine.class.should == Class
|
6
15
|
end
|
7
16
|
|
8
17
|
describe "#initialize" do
|
9
|
-
before(:each) do
|
10
|
-
@path= "#{FoldFixtureRoot}/fixture.target.fold"
|
11
|
-
@engine= Fold::Engine.new File.read(@path)
|
12
|
-
end
|
13
|
-
|
14
18
|
it "sets fold content" do
|
15
19
|
@engine.instance_variable_get(:@source).should == File.read(@path)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
|
-
describe "#prepare_fold" do
|
20
|
-
before(:each) do
|
21
|
-
@path= "#{FoldFixtureRoot}/fixture.target.fold"
|
22
|
-
@engine= Fold::Engine.new File.read(@path)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "prepares fold content" do
|
26
|
-
@engine.instance_variable_get(:@prepared_source).should_not be_nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
23
|
describe "#lines" do
|
31
24
|
it "splits on line breaks" do
|
32
25
|
lines= 10
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'rspec/fold_spec_helper'
|
2
2
|
|
3
|
-
class Included
|
3
|
+
class Included
|
4
|
+
include Fold::FoldFactory
|
5
|
+
def initialize
|
6
|
+
@instance_variable = []
|
7
|
+
end
|
8
|
+
end
|
4
9
|
|
5
10
|
describe Fold::FoldFactory do
|
6
11
|
it "inherits module" do
|
@@ -37,6 +42,14 @@ describe Fold::FoldFactory, ".produce" do
|
|
37
42
|
Included.folds :Location, /^\@/
|
38
43
|
@it.produce('@LINE').is_a?(Included::Location).should == true
|
39
44
|
end
|
45
|
+
|
46
|
+
it "passes along instance variables" do
|
47
|
+
@it.produce.instance_variables.should include("@instance_variable")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "and sets up attribute accessors for them" do
|
51
|
+
@it.produce.instance_variable.should === []
|
52
|
+
end
|
40
53
|
end
|
41
54
|
|
42
55
|
|
data/rspec/fold_spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
__DIR__ = File.dirname(__FILE__)
|
3
|
+
$LOAD_PATH << "#{__DIR__}/.." unless $LOAD_PATH.include?("#{__DIR__}/..")
|
4
|
+
FoldFixtureRoot= File.expand_path("#{__DIR__}/fixtures/fold")
|
5
|
+
require "lib/fold"
|
6
|
+
require 'pathname'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collin-fold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collin Miller
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: "0"
|
32
32
|
version:
|
33
|
-
description:
|
33
|
+
description:
|
34
34
|
email: collintmiller@gmail.com
|
35
35
|
executables: []
|
36
36
|
|
@@ -47,10 +47,10 @@ files:
|
|
47
47
|
- lib/fold/abstract_fold.rb
|
48
48
|
- lib/fold/fold_factory.rb
|
49
49
|
- lib/fold/precompiler.rb
|
50
|
-
- lib/fold/engine.rb~
|
51
50
|
- rspec/fixtures
|
52
51
|
- rspec/fixtures/fold
|
53
52
|
- rspec/fixtures/fold/fixture.target.fold
|
53
|
+
- rspec/fixtures/fold/empty.target.fold
|
54
54
|
- rspec/fold_spec.rb
|
55
55
|
- rspec/fold_spec_helper.rb
|
56
56
|
- rspec/fold
|