fold 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,19 @@
1
+ ## Collin Miller claims authorship! $$$
2
+ ##### MIT license for all Earthlings ***
3
+ #### http://www.opensource.org/licenses/mit-license.php ^^^
4
+ ## Martians and Moonlings pay extra ##
5
+
6
+ #### You're in the Fold now! %%%
7
+
8
+ Inspiration provided by http://haml.hamptoncatlin.com
9
+
10
+ Example of a Fold language:
11
+ http://github.com/collin/lucky7/tree/master/lib/jass.rb
12
+
13
+ Example written in that mini-language:
14
+ http://github.com/collin/lucky7/tree/master/lib/jsspec/example.html.jass
15
+
16
+ And the rendered output for the html.jass file:
17
+ http://github.com/collin/lucky7/tree/master/vendor/js_spec/example.spec.html
18
+
19
+ :D
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'pathname'
3
+ require 'spec'
4
+
5
+ __DIR__ = Pathname.new(__FILE__).dirname
6
+
7
+
8
+ task :default => 'spec:all'
9
+
10
+ namespace :spec do
11
+
12
+ task :prepare do
13
+ @specs= Dir.glob("#{__DIR__}/rspec/**/*.rb").join(' ')
14
+ end
15
+
16
+ task :all => :prepare do
17
+ system "spec #{@specs}"
18
+ end
19
+
20
+ task :doc => :prepare do
21
+ system "spec #{@specs} --format specdoc"
22
+ end
23
+ end
24
+
25
+ task :cleanup do
26
+ Dir.glob("**/*.*~")+Dir.glob("**/*~").each{|swap|FileUtils.rm(swap, :force => true)}
27
+ end
28
+
29
+ begin
30
+ require 'jeweler'
31
+ Jeweler::Tasks.new do |gemspec|
32
+ gemspec.name = "fold"
33
+ gemspec.summary = "A toolkit for creating whitespace active mini-languages. Inspired by Haml, light on features."
34
+ # gemspec.description = "A different and possibly longer explanation of"
35
+ gemspec.email = "collintmiller@gmail.com"
36
+ gemspec.homepage = "http://github.com/collin/fold"
37
+ gemspec.authors = ["Collin Miller"]
38
+
39
+ gemspec.add_dependency('ruby2ruby', '1.2.4')
40
+ gemspec.add_dependency('ParseTree', '3.0.4')
41
+ gemspec.add_dependency('metaid', '1.0')
42
+ end
43
+ Jeweler::GemcutterTasks.new
44
+ rescue LoadError
45
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile.rb, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fold}
8
+ s.version = "0.5.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Collin Miller"]
12
+ s.date = %q{2009-11-28}
13
+ s.email = %q{collintmiller@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README"
16
+ ]
17
+ s.files = [
18
+ "README",
19
+ "Rakefile.rb",
20
+ "VERSION",
21
+ "fold.gemspec",
22
+ "lib/fold.rb",
23
+ "lib/fold/abstract_fold.rb",
24
+ "lib/fold/abstract_slice.rb",
25
+ "lib/fold/engine.rb",
26
+ "lib/fold/fold_factory.rb",
27
+ "lib/fold/precompiler.rb",
28
+ "lib/fold/slice_factory.rb",
29
+ "rspec/fixtures/fold/empty.target.fold",
30
+ "rspec/fixtures/fold/fixture.target.fold",
31
+ "rspec/fold/abstract_fold_spec.rb",
32
+ "rspec/fold/abstract_slice_spec.rb",
33
+ "rspec/fold/engine_spec.rb",
34
+ "rspec/fold/fold_factory_spec.rb",
35
+ "rspec/fold/precompiler_spec.rb",
36
+ "rspec/fold/slice_factory_spec.rb",
37
+ "rspec/fold_spec.rb",
38
+ "rspec/fold_spec_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/collin/fold}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{A toolkit for creating whitespace active mini-languages. Inspired by Haml, light on features.}
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<ruby2ruby>, ["= 1.2.4"])
52
+ s.add_runtime_dependency(%q<ParseTree>, ["= 3.0.4"])
53
+ s.add_runtime_dependency(%q<metaid>, ["= 1.0"])
54
+ else
55
+ s.add_dependency(%q<ruby2ruby>, ["= 1.2.4"])
56
+ s.add_dependency(%q<ParseTree>, ["= 3.0.4"])
57
+ s.add_dependency(%q<metaid>, ["= 1.0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<ruby2ruby>, ["= 1.2.4"])
61
+ s.add_dependency(%q<ParseTree>, ["= 3.0.4"])
62
+ s.add_dependency(%q<metaid>, ["= 1.0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+ require 'activesupport'
3
+ require 'parse_tree'
4
+ require 'parse_tree_extensions'
5
+ require 'ruby2ruby'
6
+ require 'metaid'
7
+
8
+ module Fold
9
+ def self.root
10
+ @root ||= Pathname.new(__FILE__).dirname.expand_path
11
+ end
12
+ require root+'fold/engine'
13
+ require root+'fold/abstract_fold'
14
+ require root+'fold/abstract_slice'
15
+ require root+'fold/fold_factory'
16
+ require root+'fold/slice_factory'
17
+ require root+'fold/precompiler'
18
+ end
@@ -0,0 +1,26 @@
1
+ require 'ostruct'
2
+
3
+ module Fold
4
+ class AbstractFold < OpenStruct
5
+ Regex= //
6
+ def initialize source={}
7
+ attrs= {
8
+ :text => '',
9
+ :children => [],
10
+ :tabs => -1
11
+ }.merge(source)
12
+
13
+ attrs[:text].gsub! self.class::Regex, '' if self.class.clear_match
14
+
15
+ super attrs
16
+ end
17
+
18
+ def render
19
+ text
20
+ end
21
+
22
+ def render_children
23
+ children.map{|child| child.render}
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'ostruct'
2
+
3
+ module Fold
4
+ class AbstractSlice < OpenStruct
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ module Fold
2
+ class Engine
3
+ def initialize source
4
+ @source= source
5
+ end
6
+
7
+ def lines
8
+ @source.split(/\n/).reject{|line| line.blank?}
9
+ end
10
+
11
+ def render context
12
+ precompiler = precompiler_class.new
13
+ precompiler.fold(lines).children.map do |child|
14
+ child.render(precompiler)
15
+ end
16
+ end
17
+
18
+ # *** me hard
19
+ def precompiler_class
20
+ @precompiler||= instance_eval "#{self.class.to_s.split(/::/).first}::Precompiler"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ module Fold
2
+ module FoldFactory
3
+ Indent= 2
4
+ class IndentationError < StandardError; end
5
+
6
+ def self.included klass
7
+ klass.extend ClassMethods
8
+ end
9
+
10
+ def produce line=''
11
+ tabs = count_soft_tabs(line)
12
+ line = line.sub(/^[ ]+/, '')
13
+ attrs= {
14
+ :text => line,
15
+ :tabs => tabs
16
+ }
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)
23
+ klass.new attrs
24
+ else
25
+ AbstractFold.new attrs.merge(:tabs => -1)
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
+ that = self
34
+ fold.meta_def :method_missing do |meth, *args|
35
+ return that.send(meth, *args) if that.respond_to?(meth)
36
+ super
37
+ end
38
+
39
+ fold
40
+ end
41
+
42
+ def detect_class line
43
+ return nil if line.blank?
44
+ self.class.defined_folds.reverse.detect {|fold| fold::Regex and fold::Regex.match(line)}
45
+ end
46
+
47
+ def count_soft_tabs line
48
+ spaces= line.index(/([^ ]|$)/)
49
+ raise IndentationError if spaces.odd?
50
+ spaces / Indent
51
+ end
52
+
53
+ module ClassMethods
54
+ def folds id, regex=AbstractFold::Regex, clear_match=true, &block
55
+ fold= Class.new(AbstractFold)
56
+ fold.const_set :Regex, regex
57
+
58
+ fold.send :define_method, :render, &block if block_given?
59
+ fold.class.send :define_method, :clear_match do; clear_match end
60
+
61
+ const_set id, fold
62
+ defined_folds << fold
63
+ end
64
+
65
+ def defined_folds
66
+ @folds||= []
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,58 @@
1
+ module Fold
2
+ class Precompiler
3
+ include Fold::FoldFactory
4
+ include Fold::SliceFactory
5
+
6
+ def fold lines
7
+ last_line= produce
8
+
9
+ return last_line if lines.empty?
10
+
11
+ parent_line= nil
12
+
13
+ parent_stack= []
14
+
15
+ lines.each do |text|
16
+ line = produce process(text)
17
+
18
+ indent = line.tabs - last_line.tabs
19
+
20
+ raise IndentationError if indent > 1
21
+
22
+ if step_in? indent
23
+ parent_line = last_line
24
+ parent_line.children << line
25
+ parent_stack << parent_line
26
+ end
27
+
28
+ if step_aside? indent
29
+ parent_line.children << line
30
+ end
31
+
32
+ if step_out? indent
33
+ parent_stack= parent_stack.slice 0, parent_stack.length + indent
34
+ parent_line = parent_stack.last
35
+ parent_line.children << line
36
+ end
37
+
38
+ line.parent = parent_line unless parent_line.nil?
39
+
40
+ last_line= line
41
+ end
42
+
43
+ parent_stack.first
44
+ end
45
+
46
+ def step_in? indent
47
+ indent == 1
48
+ end
49
+
50
+ def step_out? indent
51
+ indent < 0
52
+ end
53
+
54
+ def step_aside? indent
55
+ indent == 0
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,63 @@
1
+ module Fold
2
+ module SliceFactory
3
+ def self.included klass
4
+ klass.extend ClassMethods
5
+ end
6
+
7
+ def process line=''
8
+ self.class.defined_slices.each do |slice|
9
+ line.gsub! slice::Regex do |match|
10
+ text = $1
11
+ eval(slice::Block.to_ruby).call
12
+ end
13
+ end
14
+ line
15
+ end
16
+
17
+ # def produce line=''
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)
23
+ # klass.new attrs
24
+ # else
25
+ # AbstractFold.new attrs.merge(:tabs => -1)
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
+ # that = self
34
+ # fold.meta_def :method_missing do |meth, *args|
35
+ # return that.send(meth, *args) if that.respond_to?(meth)
36
+ # super
37
+ # end
38
+ #
39
+ # fold
40
+ # end
41
+
42
+ def detect_slice_class line
43
+ return nil if line.blank?
44
+ self.class.defined_slices.reverse.detect {|slice| slice::Regex and slice::Regex.match(line)}
45
+ end
46
+
47
+ module ClassMethods
48
+ def slices id, regex=AbstractSlice::Regex, &block
49
+ slice= Class.new(AbstractSlice)
50
+
51
+ slice.const_set :Regex, regex
52
+ slice.const_set :Block, block
53
+
54
+ const_set id, slice
55
+ defined_slices << slice
56
+ end
57
+
58
+ def defined_slices
59
+ @slices||= []
60
+ end
61
+ end
62
+ end
63
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ family Modena
2
+ father Dave
3
+ mother Catherine
4
+ son Carl
5
+ daughter Tena
6
+
7
+ family Tarelo
8
+ father Tyson
9
+ mother Rheida
@@ -0,0 +1,69 @@
1
+ require "ostruct"
2
+ require 'rspec/fold_spec_helper'
3
+
4
+ describe Fold::AbstractFold do
5
+ it "inherits OpenStruct" do
6
+ Fold::AbstractFold.superclass.should == OpenStruct
7
+ end
8
+ end
9
+
10
+ describe Fold::AbstractFold, ".initialize" do
11
+ it "and sets the regex" do
12
+ Fold::Precompiler.folds :What, /what/
13
+ Fold::Precompiler::What::Regex.should == /what/
14
+ end
15
+
16
+ it "and specifies whether or not to rip the match from the source" do
17
+ Fold::Precompiler.folds :Whatever, /whatever/, false
18
+ Fold::Precompiler::Whatever.clear_match.should == false
19
+ end
20
+ end
21
+
22
+ describe Fold::AbstractFold, ".render" do
23
+ it "renders cleanly" do
24
+ fold= Fold::AbstractFold.new(:text=>"LINE")
25
+ fold.render.should == "LINE"
26
+ end
27
+
28
+ it "renders from block" do
29
+ Fold::Precompiler.folds :What, /what/ do
30
+ "#{text}?"
31
+ end
32
+
33
+ what= Fold::Precompiler::What.new(:text=>'whatever')
34
+ what.render.should== "ever?"
35
+ end
36
+
37
+ it "doesn't clear match text if clear_match is false" do
38
+ Fold::Precompiler.folds :Dirty, /dirty/, false
39
+ dirty = Fold::Precompiler::Dirty.new(:text=>"dirty bird")
40
+ dirty.render.should == "dirty bird"
41
+ end
42
+
43
+ it "renders children" do
44
+ Fold::Precompiler.folds :Parent, /^parent / do
45
+ "Hey, #{text} here, my children are: #{render_children.join(', ')}"
46
+ end
47
+
48
+ Fold::Precompiler.folds :Child, /^child /
49
+
50
+ will= Fold::Precompiler::Parent.new(:text=>"Will")
51
+ will.children << Fold::Precompiler::Child.new(:text=>"Tony")
52
+ will.children << Fold::Precompiler::Child.new(:text=>"Ace")
53
+
54
+ will.render.should == "Hey, Will here, my children are: Tony, Ace"
55
+ end
56
+ end
57
+
58
+ describe Fold::AbstractFold, ".render_children" do
59
+ it "renders cleanly" do
60
+ Fold::Precompiler.folds :Parent, /^parent /
61
+ Fold::Precompiler.folds :Child, /^child /
62
+
63
+ will= Fold::Precompiler::Parent.new(:text=>"Will")
64
+ will.children << Fold::Precompiler::Child.new(:text=>"Tony")
65
+ will.children << Fold::Precompiler::Child.new(:text=>"Ace")
66
+
67
+ will.render_children.should == ["Tony", "Ace"]
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ require "ostruct"
2
+ require 'rspec/fold_spec_helper'
3
+
4
+ describe Fold::AbstractSlice do
5
+ it "inherits OpenStruct" do
6
+ Fold::AbstractSlice.superclass.should == OpenStruct
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'rspec/fold_spec_helper'
2
+
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
+
13
+ it "inherits Module" do
14
+ Fold::Engine.class.should == Class
15
+ end
16
+
17
+ describe "#initialize" do
18
+ it "sets fold content" do
19
+ @engine.instance_variable_get(:@source).should == File.read(@path)
20
+ end
21
+ end
22
+
23
+ describe "#lines" do
24
+ it "splits on line breaks" do
25
+ lines= 10
26
+ src= "LINE\n" * lines
27
+ en= Fold::Engine.new src
28
+ en.lines.length.should == lines
29
+ end
30
+
31
+ it "rejects whitespace only lines" do
32
+ src= "LINE\n \nLINE\n\t\n\t\nwhatup?"
33
+ en= Fold::Engine.new src
34
+ en.lines.length.should == 3
35
+ end
36
+ end
37
+
38
+ describe "#render" do
39
+ it "renders spec" do
40
+ Fold::Precompiler.folds :Line, //
41
+ source= File.read "#{FoldFixtureRoot}/fixture.target.fold"
42
+ en= Fold::Engine.new source
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,85 @@
1
+ require 'rspec/fold_spec_helper'
2
+
3
+ class Included
4
+ include Fold::FoldFactory
5
+ def initialize
6
+ @instance_variable = []
7
+ end
8
+
9
+ def passed
10
+ :passed
11
+ end
12
+ end
13
+
14
+ describe Fold::FoldFactory do
15
+ it "inherits module" do
16
+ Fold::FoldFactory.class.should == Module
17
+ end
18
+ end
19
+
20
+ describe Fold::FoldFactory, ".count_soft_tabs" do
21
+ before(:each) {@it= Included.new}
22
+
23
+ it "counts one soft tabs" do
24
+ @it.count_soft_tabs(" LINE").should == 1
25
+ end
26
+
27
+ it "counts tree soft tabs" do
28
+ @it.count_soft_tabs(" " * 3 + "LINE").should == 3
29
+ end
30
+
31
+ it "raises IndentationError on odd spaced indentation" do
32
+ lambda {
33
+ @it.count_soft_tabs(" LINE")
34
+ }.should raise_error(Fold::Precompiler::IndentationError)
35
+ end
36
+ end
37
+
38
+ describe Fold::FoldFactory, ".produce" do
39
+ before(:each) {@it= Included.new}
40
+
41
+ it "folds abstractly" do
42
+ @it.produce.is_a?(Fold::AbstractFold).should == true
43
+ end
44
+
45
+ it "folds other folds" do
46
+ Included.folds :Location, /^\@/
47
+ @it.produce('@LINE').is_a?(Included::Location).should == true
48
+ end
49
+
50
+ it "passes along instance variables" do
51
+ @it.produce.instance_variables.should include("@instance_variable")
52
+ end
53
+
54
+ it "methods fall through" do
55
+ @it.produce.passed.should == :passed
56
+ end
57
+
58
+ it "and sets up attribute accessors for them" do
59
+ @it.produce.instance_variable.should === []
60
+ end
61
+ end
62
+
63
+ #describe Fold::Precompiler::Action::Regex do
64
+ # it "matches !LINE" do
65
+ # Fold::Precompiler::Action::Regex.should match("!LINE")
66
+ # end
67
+ #end
68
+ #
69
+ #describe Fold::Precompiler::Selector::Regex do
70
+ # it "matches ?LINE" do
71
+ # Fold::Precompiler::Selector::Regex.should match("?LINE")
72
+ # end
73
+ #end
74
+ #
75
+ #describe Fold::Precompiler::Group::Regex do
76
+ # it "matches describe LINE" do
77
+ # Fold::Precompiler::Group::Regex.should match("describe LINE")
78
+ # end
79
+ #end
80
+ #
81
+ #describe Fold::Precompiler::Example::Regex do
82
+ # it "matches it LINE" do
83
+ # Fold::Precompiler::Example::Regex.should match("it LINE")
84
+ # end
85
+ #end
@@ -0,0 +1,132 @@
1
+ require 'rspec/fold_spec_helper'
2
+
3
+ describe Fold::Precompiler do
4
+ it "inherits module" do
5
+ Fold::Precompiler.class.should == Class
6
+ end
7
+ end
8
+
9
+ class Confused < Fold::Precompiler
10
+ folds :Line, //
11
+ folds :What, /what/
12
+
13
+ slices :Octothorp, /#([\w]+)/ do
14
+ "octothorpedo:#{text}"
15
+ end
16
+ end
17
+
18
+ describe Fold::Precompiler, ".folds" do
19
+ it "generates AbstractFold subclasses" do
20
+ Confused::What.superclass.should == Fold::AbstractFold
21
+ end
22
+
23
+ it "in the appropriate namespace" do
24
+ Confused::What.should_not be_nil
25
+ end
26
+
27
+ it "pushes to defined_folds" do
28
+ Confused.defined_folds.should include(Confused::What)
29
+ end
30
+ end
31
+
32
+ describe Fold::Precompiler, ".fold" do
33
+ before(:each) do
34
+ @it= Confused.new
35
+ end
36
+
37
+ it "has notion of top level" do
38
+ en= Fold::Engine.new %{
39
+ LINE 1
40
+ LINE 2
41
+ LINE 3
42
+ LINE 4
43
+ LINE 5
44
+ LINE 6
45
+
46
+ LINE 7
47
+ LINE 8
48
+ LINE 9
49
+ }
50
+ @it.fold(en.lines).children.length.should == 3
51
+ end
52
+
53
+ it "children can be orphans" do
54
+ en = Fold::Engine.new "LINE 1"
55
+ @it.fold(en.lines).parent.should == nil
56
+ end
57
+
58
+ it "lets children know about their parents" do
59
+ en = Fold::Engine.new %{
60
+ Line 1
61
+ Line 2
62
+ Line 3
63
+ }
64
+
65
+ folded = @it.fold(en.lines)
66
+ folded.children.first.parent.should == folded
67
+ end
68
+
69
+ it "barfs on innappropriate indentation" do
70
+ en= Fold::Engine.new %{
71
+ LINE 1
72
+ LINE 2
73
+ }
74
+ lambda {
75
+ @it.fold(en.lines)
76
+ }.should raise_error(Confused::IndentationError)
77
+ end
78
+
79
+ it "doesn't choke with empty source" do
80
+ @it.fold([]).should_not be_nil
81
+ end
82
+ end
83
+
84
+ describe Fold::Precompiler, ".step_in?" do
85
+ before(:each) do
86
+ @it= Confused.new
87
+ end
88
+
89
+ it "must indent 1" do
90
+ @it.step_in?(1).should == true
91
+ end
92
+
93
+ it "no more" do
94
+ @it.step_in?(2).should == false
95
+ end
96
+
97
+ it "no less" do
98
+ @it.step_in?(0).should == false
99
+ end
100
+ end
101
+
102
+ describe Fold::Precompiler, ".step_out?" do
103
+ before(:each) do
104
+ @it= Confused.new
105
+ end
106
+
107
+ it "must indent < 0" do
108
+ @it.step_out?(-1).should == true
109
+ end
110
+
111
+ it "cannot indent > 0" do
112
+ @it.step_out?(0).should == false
113
+ end
114
+ end
115
+
116
+ describe Fold::Precompiler, ".step_aside?" do
117
+ before(:each) do
118
+ @it= Confused.new
119
+ end
120
+
121
+ it "must indent 0" do
122
+ @it.step_aside?(0).should == true
123
+ end
124
+
125
+ it "no more" do
126
+ @it.step_aside?(1).should == false
127
+ end
128
+
129
+ it "no less" do
130
+ @it.step_aside?(-1).should == false
131
+ end
132
+ end
@@ -0,0 +1,40 @@
1
+ require 'rspec/fold_spec_helper'
2
+
3
+ class Included
4
+ include Fold::FoldFactory
5
+ include Fold::SliceFactory
6
+
7
+ slices :Interpolation, /#\{(.*?)\}/ do
8
+ text
9
+ end
10
+
11
+ def initialize
12
+ @instance_variable = []
13
+ end
14
+
15
+ def passed
16
+ :passed
17
+ end
18
+ end
19
+
20
+ describe Fold::SliceFactory do
21
+ it "inherits module" do
22
+ Fold::SliceFactory.class.should == Module
23
+ end
24
+
25
+ before(:each) do
26
+ @it = Included.new
27
+ end
28
+
29
+ it "has list of included slices" do
30
+ Included.defined_slices.should include(Included::Interpolation)
31
+ end
32
+
33
+ it "generates constant" do
34
+ Included::Interpolation.should_not be_nil
35
+ end
36
+
37
+ it "replaces items in a string" do
38
+ @it.process('#{hey} whats #{up}').should == "hey whats up"
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ require 'rspec/fold_spec_helper'
2
+
3
+ describe Fold do
4
+ it "inherits Module" do
5
+ Fold.class.should == Module
6
+ end
7
+
8
+ it "has an Engine Class" do
9
+ Fold.constants.should include("Engine")
10
+ end
11
+
12
+ it "has a precompiler class" do
13
+ Fold.constants.should include("Precompiler")
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ __DIR__ = File.dirname(__FILE__)
3
+ $LOAD_PATH << "#{__DIR__}/.." unless $LOAD_PATH.include?("#{__DIR__}/..")
4
+ FoldFixtureRoot= File.expand_path("#{__DIR__}/fixtures/fold")
5
+
6
+ require "lib/fold"
7
+ require 'pathname'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Collin Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-28 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby2ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ParseTree
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: metaid
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ version: "1.0"
44
+ version:
45
+ description:
46
+ email: collintmiller@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README
53
+ files:
54
+ - README
55
+ - Rakefile.rb
56
+ - VERSION
57
+ - fold.gemspec
58
+ - lib/fold.rb
59
+ - lib/fold/abstract_fold.rb
60
+ - lib/fold/abstract_slice.rb
61
+ - lib/fold/engine.rb
62
+ - lib/fold/fold_factory.rb
63
+ - lib/fold/precompiler.rb
64
+ - lib/fold/slice_factory.rb
65
+ - rspec/fixtures/fold/empty.target.fold
66
+ - rspec/fixtures/fold/fixture.target.fold
67
+ - rspec/fold/abstract_fold_spec.rb
68
+ - rspec/fold/abstract_slice_spec.rb
69
+ - rspec/fold/engine_spec.rb
70
+ - rspec/fold/fold_factory_spec.rb
71
+ - rspec/fold/precompiler_spec.rb
72
+ - rspec/fold/slice_factory_spec.rb
73
+ - rspec/fold_spec.rb
74
+ - rspec/fold_spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/collin/fold
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A toolkit for creating whitespace active mini-languages. Inspired by Haml, light on features.
103
+ test_files: []
104
+