kcomp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +50 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +23 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/bin/kcomp +4 -0
  10. data/kcomp.gemspec +96 -0
  11. data/lib/errors.rb +5 -0
  12. data/lib/kcomp.rb +146 -0
  13. data/spec/kcomp_spec.rb +238 -0
  14. data/spec/spec_helper.rb +29 -0
  15. data/spec/support/test-dest/.gitkeep +1 -0
  16. data/spec/support/test-src/_partial1.kit +1 -0
  17. data/spec/support/test-src/_partial2.kit +1 -0
  18. data/spec/support/test-src/_partial3.kit +1 -0
  19. data/spec/support/test-src/inc1.kit +3 -0
  20. data/spec/support/test-src/inc10.kit +3 -0
  21. data/spec/support/test-src/inc11.kit +1 -0
  22. data/spec/support/test-src/inc12.kit +1 -0
  23. data/spec/support/test-src/inc2.kit +3 -0
  24. data/spec/support/test-src/inc4.kit +3 -0
  25. data/spec/support/test-src/inc5.kit +1 -0
  26. data/spec/support/test-src/inc7.kit +1 -0
  27. data/spec/support/test-src/inc8.kit +1 -0
  28. data/spec/support/test-src/inc9.kit +1 -0
  29. data/spec/support/test-src/somedir/inc3.kit +3 -0
  30. data/spec/support/test-src/somedir/inc6.kit +1 -0
  31. data/spec/support/test-src/test-inclusion.kit +39 -0
  32. data/spec/support/test-src-cyclic-1/inc1.kit +3 -0
  33. data/spec/support/test-src-cyclic-1/test-inclusion.kit +5 -0
  34. data/spec/support/test-src-cyclic-2/inc1.kit +3 -0
  35. data/spec/support/test-src-cyclic-2/inc2.kit +3 -0
  36. data/spec/support/test-src-cyclic-2/test-inclusion.kit +5 -0
  37. data/spec/support/test-src-missing-dependency/test.kit +5 -0
  38. data/spec/support/test-src-undefined-variable/test.kit +5 -0
  39. metadata +201 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "rgl", "~>0.4.0"
9
+
10
+ group :development do
11
+ gem "pry", "~> 0.9.12"
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.3.0"
15
+ gem "jeweler", "~> 1.8.4"
16
+ gem "simplecov", ">= 0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.0.9)
5
+ diff-lcs (1.1.3)
6
+ git (1.2.5)
7
+ jeweler (1.8.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rdoc
12
+ json (1.7.7)
13
+ method_source (0.8.1)
14
+ multi_json (1.7.2)
15
+ pry (0.9.12)
16
+ coderay (~> 1.0.5)
17
+ method_source (~> 0.8)
18
+ slop (~> 3.4)
19
+ rake (10.0.4)
20
+ rdoc (3.12.2)
21
+ json (~> 1.4)
22
+ rgl (0.4.0)
23
+ rake
24
+ stream (>= 0.5)
25
+ rspec (2.8.0)
26
+ rspec-core (~> 2.8.0)
27
+ rspec-expectations (~> 2.8.0)
28
+ rspec-mocks (~> 2.8.0)
29
+ rspec-core (2.8.0)
30
+ rspec-expectations (2.8.0)
31
+ diff-lcs (~> 1.1.2)
32
+ rspec-mocks (2.8.0)
33
+ simplecov (0.7.1)
34
+ multi_json (~> 1.0)
35
+ simplecov-html (~> 0.7.1)
36
+ simplecov-html (0.7.1)
37
+ slop (3.4.4)
38
+ stream (0.5)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.3.0)
45
+ jeweler (~> 1.8.4)
46
+ pry (~> 0.9.12)
47
+ rdoc (~> 3.12)
48
+ rgl (~> 0.4.0)
49
+ rspec (~> 2.8.0)
50
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Jeremy Holland
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = kcomp
2
+
3
+ This is a simple command-line compiler for CodeKit .kit files for those of us who don't have it, aren't on Macs, or simply prefer the command line Usage is pretty simple:
4
+
5
+ kcomp SRC-DIR DEST-DIR
6
+
7
+ if the arguemnts are omitted, they will both be assumed to be the CWD. Documentation on the .kit file format can be found at http://incident57.com/codekit/kit.php.
8
+
9
+ == Contributing to kcomp
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
13
+ * Fork the project.
14
+ * Start a feature/bugfix branch.
15
+ * Commit and push until you are happy with your contribution.
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2013 Jeremy Holland. See LICENSE.txt for
22
+ further details.
23
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "kcomp"
18
+ gem.homepage = "http://github.com/awebneck/kcomp"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Codekit .kit file command-line compiler}
21
+ gem.description = %Q{Codekit .kit file command-line compiler}
22
+ gem.email = "jeremy@jeremypholland.com"
23
+ gem.authors = ["Jeremy Holland"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "kcomp #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/kcomp ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/kcomp"
3
+
4
+ KComp.compile! ARGV[0] || ".", ARGV[1] || "."
data/kcomp.gemspec ADDED
@@ -0,0 +1,96 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "kcomp"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeremy Holland"]
12
+ s.date = "2013-04-06"
13
+ s.description = "Codekit .kit file command-line compiler"
14
+ s.email = "jeremy@jeremypholland.com"
15
+ s.executables = ["kcomp"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/kcomp",
30
+ "kcomp.gemspec",
31
+ "lib/errors.rb",
32
+ "lib/kcomp.rb",
33
+ "spec/kcomp_spec.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/support/test-dest/.gitkeep",
36
+ "spec/support/test-src-cyclic-1/inc1.kit",
37
+ "spec/support/test-src-cyclic-1/test-inclusion.kit",
38
+ "spec/support/test-src-cyclic-2/inc1.kit",
39
+ "spec/support/test-src-cyclic-2/inc2.kit",
40
+ "spec/support/test-src-cyclic-2/test-inclusion.kit",
41
+ "spec/support/test-src-missing-dependency/test.kit",
42
+ "spec/support/test-src-undefined-variable/test.kit",
43
+ "spec/support/test-src/_partial1.kit",
44
+ "spec/support/test-src/_partial2.kit",
45
+ "spec/support/test-src/_partial3.kit",
46
+ "spec/support/test-src/inc1.kit",
47
+ "spec/support/test-src/inc10.kit",
48
+ "spec/support/test-src/inc11.kit",
49
+ "spec/support/test-src/inc12.kit",
50
+ "spec/support/test-src/inc2.kit",
51
+ "spec/support/test-src/inc4.kit",
52
+ "spec/support/test-src/inc5.kit",
53
+ "spec/support/test-src/inc7.kit",
54
+ "spec/support/test-src/inc8.kit",
55
+ "spec/support/test-src/inc9.kit",
56
+ "spec/support/test-src/somedir/inc3.kit",
57
+ "spec/support/test-src/somedir/inc6.kit",
58
+ "spec/support/test-src/test-inclusion.kit"
59
+ ]
60
+ s.homepage = "http://github.com/awebneck/kcomp"
61
+ s.licenses = ["MIT"]
62
+ s.require_paths = ["lib"]
63
+ s.rubygems_version = "1.8.23"
64
+ s.summary = "Codekit .kit file command-line compiler"
65
+
66
+ if s.respond_to? :specification_version then
67
+ s.specification_version = 3
68
+
69
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
70
+ s.add_runtime_dependency(%q<rgl>, ["~> 0.4.0"])
71
+ s.add_development_dependency(%q<pry>, ["~> 0.9.12"])
72
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
73
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
74
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.0"])
75
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
76
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<rgl>, ["~> 0.4.0"])
79
+ s.add_dependency(%q<pry>, ["~> 0.9.12"])
80
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
81
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.3.0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
84
+ s.add_dependency(%q<simplecov>, [">= 0"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<rgl>, ["~> 0.4.0"])
88
+ s.add_dependency(%q<pry>, ["~> 0.9.12"])
89
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
90
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
91
+ s.add_dependency(%q<bundler>, ["~> 1.3.0"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
93
+ s.add_dependency(%q<simplecov>, [">= 0"])
94
+ end
95
+ end
96
+
data/lib/errors.rb ADDED
@@ -0,0 +1,5 @@
1
+ class KComp
2
+ class MissingDependencyError < Exception; end
3
+ class CyclicDependencyError < Exception; end
4
+ class UndefinedVariableError < Exception; end
5
+ end
data/lib/kcomp.rb ADDED
@@ -0,0 +1,146 @@
1
+ require 'rgl/adjacency'
2
+ require 'rgl/topsort'
3
+ require 'fileutils'
4
+ require File.dirname(__FILE__) + "/errors"
5
+
6
+ class KComp
7
+ def initialize(src, dest)
8
+ @depdg = RGL::DirectedAdjacencyGraph.new
9
+ @texts = {}
10
+ @ctexts = {}
11
+ @vars = {}
12
+ @src = src = src =~ /\/$/ ? src : src + "/"
13
+ @dest = dest = dest =~ /\/$/ ? dest : dest + "/"
14
+ build_vertices src
15
+ @vertices = @depdg.to_a
16
+ build_edges src
17
+ check_for_cycles
18
+ @tsort = @depdg.topsort_iterator
19
+ @reversedg = @depdg.reverse
20
+ @rtsort = @reversedg.topsort_iterator
21
+ define_variables
22
+ end
23
+
24
+ def dependency_digraph
25
+ @depdg
26
+ end
27
+
28
+ def reverse_dependency_digraph
29
+ @reversedg
30
+ end
31
+
32
+ def files
33
+ @tsort.to_a
34
+ end
35
+
36
+ def compile!
37
+ compile_files(@dest)
38
+ puts "Compilation complete"
39
+ end
40
+
41
+ private
42
+ def define_variables
43
+ @tsort.each do |v|
44
+ rf = f = @texts[v]
45
+ vars = {}
46
+ f.scan(/(<!-- ?[$@]([A-Za-z_][A-Za-z0-9_\-]*) ?[ :=] *(.+) *-->)/).each do |var|
47
+ vars[var[1]] = var.last.strip
48
+ rf.gsub! var.first, ""
49
+ end
50
+ define_variables_for_vertex v, vars
51
+ end
52
+ end
53
+
54
+ def define_variables_for_vertex(v, vars)
55
+ @vars[v] ||= {}
56
+ @vars[v].merge! vars
57
+ @depdg.adjacent_vertices(v).each do |dep|
58
+ define_variables_for_vertex dep, vars
59
+ end
60
+ end
61
+
62
+ def compile_files(dest)
63
+ @rtsort.each do |v|
64
+ rf = f = @texts[v]
65
+ f.scan(/(<!--!!! (.+) !!!-->)/).each do |import|
66
+ rf.gsub! import.first, @ctexts[import.last]
67
+ end
68
+ f.scan(/(<!-- ?[$@]([A-Za-z_][A-Za-z0-9_\-]*) ?-->)/).each do |import|
69
+ if @vars[v][import.last].nil?
70
+ raise UndefinedVariableError, "Variable #{import.last} not defined."
71
+ end
72
+ rf.gsub! import.first, @vars[v][import.last]
73
+ end
74
+ @ctexts[v] = rf.gsub(/\n+/, "\n")
75
+ if (v !~ /_[^\/]+\.kit$/)
76
+ filename = dest + v.gsub(@src, "").gsub(/\.kit$/, ".html")
77
+ dirname = filename.gsub(/\/[^\/]+$/, "")
78
+ puts "Compiling #{filename}"
79
+ unless Dir.exists?(dirname)
80
+ FileUtils.mkdir_p dirname
81
+ end
82
+ File.open(filename, 'w+') do |file|
83
+ file.write @ctexts[v]
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def check_for_cycles
90
+ cycle = @depdg.cycles.first
91
+ unless cycle.nil?
92
+ last = cycle.pop
93
+ text = cycle.join(", ")
94
+ text += (cycle.length > 1 ? ", and " : " and ") + last
95
+ raise CyclicDependencyError, "A cyclic dependency exists between: #{text}."
96
+ end
97
+ end
98
+
99
+ def build_vertices(src)
100
+ Dir.entries(src).each do |entry|
101
+ if Dir.exists?(src + entry) && ![".", ".."].include?(entry)
102
+ build_vertices(src + entry + "/")
103
+ elsif entry =~ /\.kit$/
104
+ @depdg.add_vertex src + entry
105
+ end
106
+ end
107
+ end
108
+
109
+ def build_edges(src)
110
+ @depdg.vertices.each do |v|
111
+ add_edges(src, v)
112
+ end
113
+ end
114
+
115
+ def add_edges(src, vertex)
116
+ rf = f = File.read(vertex)
117
+ f.scan(/(<!-- ?@(?:import|include) ['"]?((?:[A-Za-z0-9_\/\-.]+(?:, *)?)+)['"]? ?-->)/).each do |import|
118
+ repl = []
119
+ import.last.split(/, */).each do |incl|
120
+ match = nil
121
+ if @vertices.include?(src + incl)
122
+ match = src + incl
123
+ elsif @vertices.include?(src + "_" + incl)
124
+ match = src + "_" + incl
125
+ else
126
+ match = @vertices.select { |v| v =~ /#{incl}$/ }.first
127
+ if match.nil?
128
+ match = @vertices.select { |v| v =~ /_#{incl}$/ }.first
129
+ end
130
+ end
131
+ if match.nil?
132
+ raise MissingDependencyError, "File #{vertex} depends upon #{incl}, but no such file was found."
133
+ end
134
+ @depdg.add_edge vertex, match
135
+ repl << match
136
+ end
137
+ rf.gsub! import.first, repl.map { |r| "<!--!!! #{r} !!!-->" }.join("\n")
138
+ end
139
+ @texts[vertex] = rf
140
+ end
141
+
142
+ def self.compile!(src, dest)
143
+ kc = KComp.new src, dest
144
+ kc.compile!
145
+ end
146
+ end
@@ -0,0 +1,238 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe KComp do
4
+ describe "constructor" do
5
+ it "should raise a CyclicDependencyError if there are cyclic dependencies in the src files of the provided directory" do
6
+ lambda { KComp.new CYCLIC_SRC_1, DEST }.should raise_error KComp::CyclicDependencyError
7
+ lambda { KComp.new CYCLIC_SRC_2, DEST }.should raise_error KComp::CyclicDependencyError
8
+ end
9
+
10
+ it "should raise a MissingDependencyError if there are imported files that can't be found" do
11
+ lambda { KComp.new MISSING_DEP_SRC, DEST }.should raise_error KComp::MissingDependencyError
12
+ end
13
+ end
14
+
15
+ describe "instance methods" do
16
+ let(:comp) { KComp.new GOOD_SRC, DEST }
17
+ let(:undef) { KComp.new UNDEFINED_VAR_SRC, DEST }
18
+
19
+ describe "dependency_digraph" do
20
+ let(:dg) { comp.dependency_digraph }
21
+ let(:adjv) { dg.adjacent_vertices(GOOD_SRC + "/test-inclusion.kit") }
22
+ it "should contain a node for each .kit file in the directory" do
23
+ dg.should include(GOOD_SRC + "/_partial1.kit")
24
+ dg.should include(GOOD_SRC + "/_partial2.kit")
25
+ dg.should include(GOOD_SRC + "/_partial3.kit")
26
+ dg.should include(GOOD_SRC + "/inc1.kit")
27
+ dg.should include(GOOD_SRC + "/inc2.kit")
28
+ dg.should include(GOOD_SRC + "/somedir/inc3.kit")
29
+ dg.should include(GOOD_SRC + "/inc4.kit")
30
+ dg.should include(GOOD_SRC + "/inc5.kit")
31
+ dg.should include(GOOD_SRC + "/somedir/inc6.kit")
32
+ dg.should include(GOOD_SRC + "/inc7.kit")
33
+ dg.should include(GOOD_SRC + "/inc8.kit")
34
+ dg.should include(GOOD_SRC + "/inc9.kit")
35
+ dg.should include(GOOD_SRC + "/inc10.kit")
36
+ dg.should include(GOOD_SRC + "/inc11.kit")
37
+ dg.should include(GOOD_SRC + "/inc12.kit")
38
+ dg.should include(GOOD_SRC + "/test-inclusion.kit")
39
+ end
40
+
41
+ it "should have directed edges indicating dependency relations" do
42
+ adjv.should include(GOOD_SRC + "/_partial1.kit")
43
+ adjv.should include(GOOD_SRC + "/_partial2.kit")
44
+ adjv.should include(GOOD_SRC + "/inc1.kit")
45
+ adjv.should include(GOOD_SRC + "/inc2.kit")
46
+ adjv.should include(GOOD_SRC + "/somedir/inc3.kit")
47
+ adjv.should include(GOOD_SRC + "/inc4.kit")
48
+ adjv.should include(GOOD_SRC + "/inc5.kit")
49
+ adjv.should include(GOOD_SRC + "/somedir/inc6.kit")
50
+ adjv.should include(GOOD_SRC + "/inc7.kit")
51
+ adjv.should include(GOOD_SRC + "/inc8.kit")
52
+ adjv.should include(GOOD_SRC + "/inc9.kit")
53
+ adjv.should include(GOOD_SRC + "/inc10.kit")
54
+ end
55
+
56
+ it "should not have any directed edges for undependent or indirectly dependent files" do
57
+ adjv = dg.adjacent_vertices(GOOD_SRC + "/test-inclusion.kit")
58
+ adjv.should_not include(GOOD_SRC + "/test-inclusion.kit")
59
+ adjv.should_not include(GOOD_SRC + "/inc11.kit")
60
+ adjv.should_not include(GOOD_SRC + "/inc12.kit")
61
+ adjv.should_not include(GOOD_SRC + "/_partial3.kit")
62
+ end
63
+ end
64
+
65
+ describe "reverse_dependency_digraph" do
66
+ let(:dg) { comp.reverse_dependency_digraph }
67
+ let(:adjv1) { dg.adjacent_vertices(GOOD_SRC + "/inc4.kit") }
68
+ let(:adjv2) { dg.adjacent_vertices(GOOD_SRC + "/inc11.kit") }
69
+ let(:adjv3) { dg.adjacent_vertices(GOOD_SRC + "/_partial3.kit") }
70
+
71
+ it "should contain a node for each .kit file in the directory" do
72
+ dg.should include(GOOD_SRC + "/_partial1.kit")
73
+ dg.should include(GOOD_SRC + "/_partial2.kit")
74
+ dg.should include(GOOD_SRC + "/_partial3.kit")
75
+ dg.should include(GOOD_SRC + "/inc1.kit")
76
+ dg.should include(GOOD_SRC + "/inc2.kit")
77
+ dg.should include(GOOD_SRC + "/somedir/inc3.kit")
78
+ dg.should include(GOOD_SRC + "/inc4.kit")
79
+ dg.should include(GOOD_SRC + "/inc5.kit")
80
+ dg.should include(GOOD_SRC + "/somedir/inc6.kit")
81
+ dg.should include(GOOD_SRC + "/inc7.kit")
82
+ dg.should include(GOOD_SRC + "/inc8.kit")
83
+ dg.should include(GOOD_SRC + "/inc9.kit")
84
+ dg.should include(GOOD_SRC + "/inc10.kit")
85
+ dg.should include(GOOD_SRC + "/inc11.kit")
86
+ dg.should include(GOOD_SRC + "/inc12.kit")
87
+ dg.should include(GOOD_SRC + "/test-inclusion.kit")
88
+ end
89
+
90
+ it "should have directed edges indicating dependent relations" do
91
+ adjv1.should include(GOOD_SRC + "/test-inclusion.kit")
92
+ adjv2.should include(GOOD_SRC + "/inc10.kit")
93
+ adjv3.should include(GOOD_SRC + "/inc10.kit")
94
+ end
95
+
96
+ it "should not have any directed edges for undependent or indirectly dependent files" do
97
+ adjv1.should_not include(GOOD_SRC + "/inc10.kit")
98
+ adjv2.should_not include(GOOD_SRC + "/test-inclusion.kit")
99
+ adjv3.should_not include(GOOD_SRC + "/test-inclusion.kit")
100
+ end
101
+ end
102
+
103
+ describe "files" do
104
+ let(:files) { comp.files }
105
+
106
+ it "should return an array of all .kit files" do
107
+ files.should include(GOOD_SRC + "/_partial1.kit")
108
+ files.should include(GOOD_SRC + "/_partial2.kit")
109
+ files.should include(GOOD_SRC + "/_partial3.kit")
110
+ files.should include(GOOD_SRC + "/inc1.kit")
111
+ files.should include(GOOD_SRC + "/inc2.kit")
112
+ files.should include(GOOD_SRC + "/somedir/inc3.kit")
113
+ files.should include(GOOD_SRC + "/inc4.kit")
114
+ files.should include(GOOD_SRC + "/inc5.kit")
115
+ files.should include(GOOD_SRC + "/somedir/inc6.kit")
116
+ files.should include(GOOD_SRC + "/inc7.kit")
117
+ files.should include(GOOD_SRC + "/inc8.kit")
118
+ files.should include(GOOD_SRC + "/inc9.kit")
119
+ files.should include(GOOD_SRC + "/inc10.kit")
120
+ files.should include(GOOD_SRC + "/inc11.kit")
121
+ files.should include(GOOD_SRC + "/inc12.kit")
122
+ files.should include(GOOD_SRC + "/test-inclusion.kit")
123
+ end
124
+
125
+ it "should order the files topologically by dependency" do
126
+ files.index(GOOD_SRC + "/_partial3.kit").should > files.index(GOOD_SRC + "/inc10.kit")
127
+ files.index(GOOD_SRC + "/inc11.kit").should > files.index(GOOD_SRC + "/inc10.kit")
128
+ files.index(GOOD_SRC + "/_partial1.kit").should > files.index(GOOD_SRC + "/test-inclusion.kit")
129
+ files.index(GOOD_SRC + "/inc10.kit").should > files.index(GOOD_SRC + "/test-inclusion.kit")
130
+ end
131
+ end
132
+
133
+ describe "compile!" do
134
+
135
+ it "should create any destination directories it needs (as dictated by the source directory structure)" do
136
+ FileUtils.rm_rf DEST + "/*"
137
+ capture_stdout do
138
+ comp.compile!
139
+ end
140
+ Dir.exists?(DEST + "/somedir").should be_true
141
+ end
142
+
143
+ it "should create a single html file for each regular kit file" do
144
+ File.exists?(DEST + "/inc1.html").should be_true
145
+ File.exists?(DEST + "/inc2.html").should be_true
146
+ File.exists?(DEST + "/somedir/inc3.html").should be_true
147
+ File.exists?(DEST + "/inc4.html").should be_true
148
+ File.exists?(DEST + "/inc5.html").should be_true
149
+ File.exists?(DEST + "/somedir/inc6.html").should be_true
150
+ File.exists?(DEST + "/inc7.html").should be_true
151
+ File.exists?(DEST + "/inc8.html").should be_true
152
+ File.exists?(DEST + "/inc9.html").should be_true
153
+ File.exists?(DEST + "/inc10.html").should be_true
154
+ File.exists?(DEST + "/inc11.html").should be_true
155
+ File.exists?(DEST + "/inc12.html").should be_true
156
+ File.exists?(DEST + "/test-inclusion.html").should be_true
157
+ end
158
+
159
+ it "should not create an html file for partials" do
160
+ File.exists?(DEST + "/partial1.html").should be_false
161
+ File.exists?(DEST + "/partial2.html").should be_false
162
+ File.exists?(DEST + "/partial3.html").should be_false
163
+ end
164
+
165
+ describe "generated files" do
166
+ it "should contain any valid variable references" do
167
+ File.read(DEST + "/inc1.html").should =~ /VAR 1/
168
+ File.read(DEST + "/inc2.html").should =~ /VAR 2/
169
+ File.read(DEST + "/somedir/inc3.html").should =~ /VAR 3/
170
+ File.read(DEST + "/inc4.html").should =~ /VAR 4/
171
+ f = File.read(DEST + "/test-inclusion.html")
172
+ f.should =~ /VAR 1/
173
+ f.should =~ /VAR 2/
174
+ f.should =~ /VAR 3/
175
+ f.should =~ /VAR 4/
176
+ f.should =~ /VAR 5/
177
+ f.should =~ /VAR 6/
178
+ f.should =~ /VAR 7/
179
+ f.should =~ /VAR 8/
180
+ f.should =~ /VAR 9/
181
+ f.should =~ /VAR 10/
182
+ f.should =~ /VAR 11/
183
+ f.should =~ /VAR 12/
184
+ end
185
+
186
+ it "should contain any inclusions" do
187
+ f = File.read(DEST + "/inc10.html")
188
+ f.scan(/INCLUSION 11/).length.should == 1
189
+ f.scan(/PARTIAL 3/).length.should == 1
190
+ f = File.read(DEST + "/test-inclusion.html")
191
+ f.scan(/INCLUSION 1$/).length.should == 2
192
+ f.scan(/INCLUSION 2/).length.should == 1
193
+ f.scan(/INCLUSION 3/).length.should == 1
194
+ f.scan(/INCLUSION 4/).length.should == 1
195
+ f.scan(/INCLUSION 5/).length.should == 1
196
+ f.scan(/INCLUSION 6/).length.should == 1
197
+ f.scan(/INCLUSION 7/).length.should == 1
198
+ f.scan(/INCLUSION 8/).length.should == 1
199
+ f.scan(/INCLUSION 9/).length.should == 1
200
+ f.scan(/INCLUSION 10/).length.should == 1
201
+ f.scan(/INCLUSION 11/).length.should == 1
202
+ f.scan(/PARTIAL 1/).length.should == 1
203
+ f.scan(/PARTIAL 2/).length.should == 1
204
+ f.scan(/PARTIAL 3/).length.should == 1
205
+ f.scan(/VAR 1$/).length.should == 2
206
+ f.scan(/VAR 2/).length.should == 1
207
+ f.scan(/VAR 3/).length.should == 1
208
+ f.scan(/VAR 4/).length.should == 1
209
+ f.scan(/VAR 5/).length.should == 1
210
+ f.scan(/VAR 6/).length.should == 1
211
+ f.scan(/VAR 7/).length.should == 1
212
+ f.scan(/VAR 8/).length.should == 1
213
+ f.scan(/VAR 9/).length.should == 1
214
+ f.scan(/VAR 10/).length.should == 1
215
+ f.scan(/VAR 11/).length.should == 1
216
+ f.scan(/VAR 12/).length.should == 1
217
+ end
218
+ end
219
+
220
+ it "should strip out any repeated newlines" do
221
+ f = File.read(DEST + "/test-inclusion.html")
222
+ f.should_not =~ /\n\n+/
223
+ end
224
+ end
225
+
226
+ end
227
+
228
+ describe "class methods" do
229
+ describe "compile!" do
230
+ it "should create a new KComp instance with the provided source and destination directories and delegate compilation thereto" do
231
+ kcomp = mock('KComp')
232
+ KComp.should_receive(:new).with('blah', 'hat').and_return kcomp
233
+ kcomp.should_receive(:compile!)
234
+ KComp.compile!('blah', 'hat')
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'kcomp'
5
+ require 'fileutils'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ GOOD_SRC = File.dirname(__FILE__) + "/support/test-src"
12
+ CYCLIC_SRC_1 = File.dirname(__FILE__) + "/support/test-src-cyclic-1"
13
+ CYCLIC_SRC_2 = File.dirname(__FILE__) + "/support/test-src-cyclic-2"
14
+ MISSING_DEP_SRC = File.dirname(__FILE__) + "/support/test-src-missing-dependency"
15
+ UNDEFINED_VAR_SRC = File.dirname(__FILE__) + "/support/test-src-undefined-variable"
16
+ DEST = File.dirname(__FILE__) + "/support/test-dest"
17
+
18
+ RSpec.configure do |config|
19
+ config.after :all do
20
+ FileUtils.rm_r Dir.glob(DEST + "/*")
21
+ end
22
+ end
23
+
24
+ def capture_stdout
25
+ prev = $stdout
26
+ $stdout = StringIO.new
27
+ yield
28
+ $stdout = prev
29
+ end
@@ -0,0 +1 @@
1
+ git sucks
@@ -0,0 +1 @@
1
+ PARTIAL 1
@@ -0,0 +1 @@
1
+ PARTIAL 2
@@ -0,0 +1 @@
1
+ PARTIAL 3
@@ -0,0 +1,3 @@
1
+ INCLUSION 1
2
+
3
+ <!-- @var1 -->
@@ -0,0 +1,3 @@
1
+ INCLUSION 10
2
+ <!--@include inc11.kit-->
3
+ <!--@include partial3.kit-->
@@ -0,0 +1 @@
1
+ INCLUSION 11
@@ -0,0 +1 @@
1
+ INCLUSION 12
@@ -0,0 +1,3 @@
1
+ INCLUSION 2
2
+
3
+ <!--@var2-->
@@ -0,0 +1,3 @@
1
+ INCLUSION 4
2
+
3
+ <!--$var4-->
@@ -0,0 +1 @@
1
+ INCLUSION 5
@@ -0,0 +1 @@
1
+ INCLUSION 7
@@ -0,0 +1 @@
1
+ INCLUSION 8
@@ -0,0 +1 @@
1
+ INCLUSION 9
@@ -0,0 +1,3 @@
1
+ INCLUSION 3
2
+
3
+ <!-- $var3 -->
@@ -0,0 +1 @@
1
+ INCLUSION 6
@@ -0,0 +1,39 @@
1
+ Here is a kit file
2
+
3
+ Here is a var
4
+ <!-- @var1 VAR 1 -->
5
+ <!-- @var2=VAR 2 -->
6
+ <!-- @var3:VAR 3 -->
7
+ <!--@var4 VAR 4-->
8
+ <!--@var5=VAR 5-->
9
+ <!--@var6:VAR 6-->
10
+ <!-- $var7 VAR 7 -->
11
+ <!-- $var8=VAR 8 -->
12
+ <!-- $var9:VAR 9 -->
13
+ <!--$var10 VAR 10-->
14
+ <!--$var11=VAR 11-->
15
+ <!--$var12:VAR 12-->
16
+
17
+ Here is an inclusion
18
+ <!-- @import inc1.kit -->
19
+ <!--@import inc2.kit-->
20
+ <!-- @import ./somedir/inc3.kit -->
21
+ <!-- @import partial1.kit -->
22
+
23
+ <!-- @include inc4.kit -->
24
+ <!--@include inc5.kit-->
25
+ <!-- @include ./somedir/inc6.kit -->
26
+ <!-- @include partial2.kit -->
27
+
28
+ <!-- @import inc7.kit,inc8.kit -->
29
+ <!--@include inc9.kit, inc10.kit-->
30
+
31
+ <!--@var5-->
32
+ <!--@var6-->
33
+ <!--@var7-->
34
+ <!--@var8-->
35
+ <!--@var9-->
36
+ <!--@var10-->
37
+ <!--@var11-->
38
+ <!--@var12-->
39
+ <!-- @import inc1.kit -->
@@ -0,0 +1,3 @@
1
+ INCLUSION 1
2
+
3
+ <!-- @import test-inclusion.kit -->
@@ -0,0 +1,5 @@
1
+ Here is a kit file
2
+
3
+ Here is an inclusion
4
+
5
+ <!-- @import inc1.kit -->
@@ -0,0 +1,3 @@
1
+ INCLUSION 1
2
+
3
+ <!-- @import inc2.kit -->
@@ -0,0 +1,3 @@
1
+ INCLUSION 2
2
+
3
+ <!-- @import test-inclusion.kit -->
@@ -0,0 +1,5 @@
1
+ Here is a kit file
2
+
3
+ Here is an inclusion
4
+
5
+ <!-- @import inc1.kit -->
@@ -0,0 +1,5 @@
1
+ Here is a kit file
2
+
3
+ Here is an inclusion
4
+
5
+ <!-- @import inc1.kit -->
@@ -0,0 +1,5 @@
1
+ Here is a kit file
2
+
3
+ Here is an inclusion
4
+
5
+ <!-- @undefvar -->
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kcomp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Holland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rgl
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.12
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.12
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.8.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.4
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Codekit .kit file command-line compiler
127
+ email: jeremy@jeremypholland.com
128
+ executables:
129
+ - kcomp
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.rdoc
141
+ - Rakefile
142
+ - VERSION
143
+ - bin/kcomp
144
+ - kcomp.gemspec
145
+ - lib/errors.rb
146
+ - lib/kcomp.rb
147
+ - spec/kcomp_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/support/test-dest/.gitkeep
150
+ - spec/support/test-src-cyclic-1/inc1.kit
151
+ - spec/support/test-src-cyclic-1/test-inclusion.kit
152
+ - spec/support/test-src-cyclic-2/inc1.kit
153
+ - spec/support/test-src-cyclic-2/inc2.kit
154
+ - spec/support/test-src-cyclic-2/test-inclusion.kit
155
+ - spec/support/test-src-missing-dependency/test.kit
156
+ - spec/support/test-src-undefined-variable/test.kit
157
+ - spec/support/test-src/_partial1.kit
158
+ - spec/support/test-src/_partial2.kit
159
+ - spec/support/test-src/_partial3.kit
160
+ - spec/support/test-src/inc1.kit
161
+ - spec/support/test-src/inc10.kit
162
+ - spec/support/test-src/inc11.kit
163
+ - spec/support/test-src/inc12.kit
164
+ - spec/support/test-src/inc2.kit
165
+ - spec/support/test-src/inc4.kit
166
+ - spec/support/test-src/inc5.kit
167
+ - spec/support/test-src/inc7.kit
168
+ - spec/support/test-src/inc8.kit
169
+ - spec/support/test-src/inc9.kit
170
+ - spec/support/test-src/somedir/inc3.kit
171
+ - spec/support/test-src/somedir/inc6.kit
172
+ - spec/support/test-src/test-inclusion.kit
173
+ homepage: http://github.com/awebneck/kcomp
174
+ licenses:
175
+ - MIT
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ segments:
187
+ - 0
188
+ hash: 1029961015163305883
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 1.8.23
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: Codekit .kit file command-line compiler
201
+ test_files: []