diff --git a/README.md b/README.md index a092b9d..8534d9c 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Use the `ignore` method in `controller.rb` to ignore certain paths. Ignore filenames with an underscore at the beginning: - ignore /_.*/ + ignore /\/_.*/ Priority -------- diff --git a/bin/stasis b/bin/stasis index e2773a6..0847dbd 100755 --- a/bin/stasis +++ b/bin/stasis @@ -15,13 +15,13 @@ end if opts.development? Stasis::DevMode.new(Dir.pwd, opts) elsif opts.only? && opts.public? - Stasis.new(Dir.pwd, opts[:public]).render(*opts[:only]) + Stasis.new(Dir.pwd, opts[:public], opts).render(*opts[:only]) elsif opts.only? - Stasis.new(Dir.pwd).render(*opts[:only]) -elsif opts.public? - Stasis.new(Dir.pwd, opts[:public]).render(*opts[:only]) + Stasis.new(Dir.pwd, opts).render(*opts[:only]) elsif opts.server? Stasis::Server.new(Dir.pwd, opts) +elsif opts.public? + Stasis.new(Dir.pwd, opts[:public], opts).render(*opts[:only]) else - Stasis.new(Dir.pwd).render + Stasis.new(Dir.pwd, opts).render end \ No newline at end of file diff --git a/lib/stasis.rb b/lib/stasis.rb index 89747dc..6fd7188 100644 --- a/lib/stasis.rb +++ b/lib/stasis.rb @@ -66,25 +66,29 @@ class Stasis # `Array` -- all paths in the project that Stasis will act upon. attr_accessor :paths + # `Options` -- options passed to `Stasis.new`. + attr_accessor :options + # `Array` -- `Plugin` instances. attr_accessor :plugins # `String` -- the root path passed to `Stasis.new`. attr_accessor :root - def initialize(root, destination=root+'/public') - root = File.expand_path(root) - destination = File.expand_path(destination, root) - - @destination = destination - @root = root + def initialize(root, *args) + @options = {} + @options = args.pop if args.last.is_a?(::Hash) + + @root = File.expand_path(root) + @destination = args[0] || @root + '/public' + @destination = File.expand_path(@destination, @root) # Create an `Array` of paths that Stasis will act upon. - @paths = Dir["#{root}/**/*"] + @paths = Dir["#{@root}/**/*"] # Reject paths that are directories or within the destination directory. @paths.reject! do |path| - !File.file?(path) || path[0..destination.length-1] == destination + !File.file?(path) || path[0..@destination.length-1] == @destination end # Create plugin instances. diff --git a/lib/stasis/dev_mode.rb b/lib/stasis/dev_mode.rb index 8545974..b8fb4b0 100644 --- a/lib/stasis/dev_mode.rb +++ b/lib/stasis/dev_mode.rb @@ -42,7 +42,7 @@ def initialize(dir, options={}) def render puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Regenerating #{@options[:only].empty? ? 'project' : @options[:only].join(', ')}..." begin - @stasis = Stasis.new(@dir) + @stasis = Stasis.new(@dir, @options) @stasis.render(*@options[:only]) rescue Exception => e puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Error: #{e.message}`" diff --git a/lib/stasis/server.rb b/lib/stasis/server.rb index 9d9d147..c14160c 100644 --- a/lib/stasis/server.rb +++ b/lib/stasis/server.rb @@ -11,7 +11,7 @@ def initialize(root, options={}) puts "\nStarting Stasis server (redis @ #{options[:server]})..." redis = Redis.connect(:url => "redis://#{options[:server]}") - stasis = Stasis.new(*[ root, options[:public] ].compact) + stasis = Stasis.new(*[ root, options[:public], options ].compact) begin while true @@ -32,10 +32,7 @@ def initialize(root, options={}) end if request['wait'] - response = { - :id => request['id'], - :files => files - } + response = files redis.publish(self.class.response_key(request['id']), Yajl::Encoder.encode(response)) end end diff --git a/spec/stasis/server_spec.rb b/spec/stasis/server_spec.rb index 3ee07c4..5716673 100644 --- a/spec/stasis/server_spec.rb +++ b/spec/stasis/server_spec.rb @@ -19,7 +19,7 @@ :paths => [ 'time.html.haml' ], :redis => 'localhost:6379/0', :return => true - )['files']['time.html.haml'].split("time")[1].strip + )['time.html.haml'].split("time")[1].strip time.should_not == new_time generate_files new_time_from_file = $files['time.html'].split("time")[1].strip