Skip to content

Commit

Permalink
Adding options to Stasis.new and making server response simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Aug 22, 2011
1 parent 22ff326 commit 69f9ca9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -163,7 +163,7 @@ Use the `ignore` method in `controller.rb` to ignore certain paths.


Ignore filenames with an underscore at the beginning: Ignore filenames with an underscore at the beginning:


ignore /_.*/ ignore /\/_.*/


Priority Priority
-------- --------
Expand Down
10 changes: 5 additions & 5 deletions bin/stasis
Expand Up @@ -15,13 +15,13 @@ end
if opts.development? if opts.development?
Stasis::DevMode.new(Dir.pwd, opts) Stasis::DevMode.new(Dir.pwd, opts)
elsif opts.only? && opts.public? 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? elsif opts.only?
Stasis.new(Dir.pwd).render(*opts[:only]) Stasis.new(Dir.pwd, opts).render(*opts[:only])
elsif opts.public?
Stasis.new(Dir.pwd, opts[:public]).render(*opts[:only])
elsif opts.server? elsif opts.server?
Stasis::Server.new(Dir.pwd, opts) Stasis::Server.new(Dir.pwd, opts)
elsif opts.public?
Stasis.new(Dir.pwd, opts[:public], opts).render(*opts[:only])
else else
Stasis.new(Dir.pwd).render Stasis.new(Dir.pwd, opts).render
end end
20 changes: 12 additions & 8 deletions lib/stasis.rb
Expand Up @@ -66,25 +66,29 @@ class Stasis
# `Array` -- all paths in the project that Stasis will act upon. # `Array` -- all paths in the project that Stasis will act upon.
attr_accessor :paths attr_accessor :paths


# `Options` -- options passed to `Stasis.new`.
attr_accessor :options

# `Array` -- `Plugin` instances. # `Array` -- `Plugin` instances.
attr_accessor :plugins attr_accessor :plugins


# `String` -- the root path passed to `Stasis.new`. # `String` -- the root path passed to `Stasis.new`.
attr_accessor :root attr_accessor :root


def initialize(root, destination=root+'/public') def initialize(root, *args)
root = File.expand_path(root) @options = {}
destination = File.expand_path(destination, root) @options = args.pop if args.last.is_a?(::Hash)


@destination = destination @root = File.expand_path(root)
@root = root @destination = args[0] || @root + '/public'
@destination = File.expand_path(@destination, @root)


# Create an `Array` of paths that Stasis will act upon. # 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. # Reject paths that are directories or within the destination directory.
@paths.reject! do |path| @paths.reject! do |path|
!File.file?(path) || path[0..destination.length-1] == destination !File.file?(path) || path[0..@destination.length-1] == @destination
end end


# Create plugin instances. # Create plugin instances.
Expand Down
2 changes: 1 addition & 1 deletion lib/stasis/dev_mode.rb
Expand Up @@ -42,7 +42,7 @@ def initialize(dir, options={})
def render def render
puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Regenerating #{@options[:only].empty? ? 'project' : @options[:only].join(', ')}..." puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Regenerating #{@options[:only].empty? ? 'project' : @options[:only].join(', ')}..."
begin begin
@stasis = Stasis.new(@dir) @stasis = Stasis.new(@dir, @options)
@stasis.render(*@options[:only]) @stasis.render(*@options[:only])
rescue Exception => e rescue Exception => e
puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Error: #{e.message}`" puts "\n[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] Error: #{e.message}`"
Expand Down
7 changes: 2 additions & 5 deletions lib/stasis/server.rb
Expand Up @@ -11,7 +11,7 @@ def initialize(root, options={})
puts "\nStarting Stasis server (redis @ #{options[:server]})..." puts "\nStarting Stasis server (redis @ #{options[:server]})..."


redis = Redis.connect(:url => "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 begin
while true while true
Expand All @@ -32,10 +32,7 @@ def initialize(root, options={})
end end


if request['wait'] if request['wait']
response = { response = files
:id => request['id'],
:files => files
}
redis.publish(self.class.response_key(request['id']), Yajl::Encoder.encode(response)) redis.publish(self.class.response_key(request['id']), Yajl::Encoder.encode(response))
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion spec/stasis/server_spec.rb
Expand Up @@ -19,7 +19,7 @@
:paths => [ 'time.html.haml' ], :paths => [ 'time.html.haml' ],
:redis => 'localhost:6379/0', :redis => 'localhost:6379/0',
:return => true :return => true
)['files']['time.html.haml'].split("time")[1].strip )['time.html.haml'].split("time")[1].strip
time.should_not == new_time time.should_not == new_time
generate_files generate_files
new_time_from_file = $files['time.html'].split("time")[1].strip new_time_from_file = $files['time.html'].split("time")[1].strip
Expand Down

0 comments on commit 69f9ca9

Please sign in to comment.