Permalink
Browse files

Adding options to Stasis.new and making server response simpler

  • Loading branch information...
1 parent 22ff326 commit 69f9ca9046cb560a746f129b522040f1e6fbddf2 @winton committed Aug 22, 2011
Showing with 22 additions and 21 deletions.
  1. +1 −1 README.md
  2. +5 −5 bin/stasis
  3. +12 −8 lib/stasis.rb
  4. +1 −1 lib/stasis/dev_mode.rb
  5. +2 −5 lib/stasis/server.rb
  6. +1 −1 spec/stasis/server_spec.rb
View
@@ -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
--------
View
@@ -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
View
@@ -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.
View
@@ -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}`"
View
@@ -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
@@ -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

0 comments on commit 69f9ca9

Please sign in to comment.