Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't allow project input/output directories to be altered.

  • Loading branch information...
commit 97f36e25800d1cc62f0f7b2d8771c90d916bc8d7 1 parent a12ad5b
@mdub authored
View
5 bin/pith
@@ -69,10 +69,7 @@ class PithCommand < Clamp::Command
signal_usage_error %(No "#{pith_dir}" directory ... this doesn't look right!)
end
puts %{Generating to "#{output_dir}"}
- @project = Pith::Project.new(
- :input_dir => input_dir, :output_dir => output_dir,
- :logger => Pith::ConsoleLogger.new
- )
+ @project = Pith::Project.new(input_dir, output_dir, :logger => Pith::ConsoleLogger.new)
end
end
View
16 features/support/env.rb
@@ -1,7 +1,7 @@
require "pathname"
class DirHash
-
+
def initialize(dir)
@dir = Pathname(dir)
end
@@ -34,7 +34,7 @@ def write(file, content, options = {})
file_path.utime(timestamp, timestamp)
end
end
-
+
end
class InternalLogger
@@ -42,13 +42,13 @@ class InternalLogger
def initialize
@messages = []
end
-
+
attr_reader :messages
-
+
def clear
@messages.clear
end
-
+
def info(message, &block)
message ||= block.call
write(message)
@@ -56,11 +56,11 @@ def info(message, &block)
alias :warn :info
alias :debug :info
-
+
def write(message)
@messages << message
end
-
+
end
$project_dir = Pathname(__FILE__).expand_path.parent.parent.parent
@@ -79,7 +79,7 @@ def write(message)
dir.rmtree if dir.exist?
dir.mkpath
end
- @project = Pith::Project.new(:input_dir => $input_dir, :output_dir => $output_dir)
+ @project = Pith::Project.new($input_dir, $output_dir)
@project.logger = InternalLogger.new
@inputs = DirHash.new($input_dir)
@outputs = DirHash.new($output_dir)
View
18 lib/pith/project.rb
@@ -11,30 +11,22 @@ class Project
DEFAULT_IGNORE_PATTERNS = ["_*", ".git", ".gitignore", ".svn", ".sass-cache", "*~", "*.sw[op]"].to_set.freeze
- def initialize(attributes = {})
+ def initialize(input_dir, output_dir = nil, attributes = {})
+ @input_dir = Pathname(input_dir)
+ @output_dir = output_dir ? Pathname(output_dir) : (input_dir + "_out")
@ignore_patterns = DEFAULT_IGNORE_PATTERNS.dup
@input_map = {}
@output_map = {}
attributes.each do |k,v|
send("#{k}=", v)
end
+ FileUtils.rm_rf(output_dir.to_s)
end
attr_reader :input_dir
- attr_reader :ignore_patterns
-
- def input_dir=(dir)
- @input_dir = Pathname(dir)
- end
-
attr_reader :output_dir
- def output_dir=(dir)
- @output_dir = Pathname(dir)
- FileUtils.rm_rf(@output_dir)
- @output_dir.mkpath
- end
-
+ attr_reader :ignore_patterns
attr_accessor :assume_content_negotiation
attr_accessor :assume_directory_index
View
2  spec/pith/input_spec.rb
@@ -5,7 +5,7 @@
describe Pith::Input do
before do
- @project = Pith::Project.new(:input_dir => $input_dir)
+ @project = Pith::Project.new($input_dir)
end
def make_input(path)
View
2  spec/pith/project_spec.rb
@@ -4,7 +4,7 @@
describe Pith::Project do
before do
- @project = Pith::Project.new(:input_dir => $input_dir, :output_dir => $output_dir)
+ @project = Pith::Project.new($input_dir, $output_dir)
end
describe "#build" do
Please sign in to comment.
Something went wrong with that request. Please try again.