Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
doc | ||
/Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bundler' | ||
Bundler.setup | ||
|
||
require './lib/proscribe' | ||
run ProScribe.rack_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'proton' | ||
require 'proton/server' | ||
require 'shake' | ||
|
||
# Module: RackApp | ||
# Provides a Rack app. | ||
# | ||
# ## Usage | ||
# | ||
# Use {ProScribe.rack_app}. | ||
# | ||
module ProScribe | ||
module RackApp | ||
def self.run! | ||
config = Shake.find_in_project("Scribefile") or return | ||
project = ProScribe::Project.new(config) | ||
project.make | ||
|
||
watcher = ProScribe::Watcher.new(project) { |_, file| puts "Updated #{file}" } | ||
|
||
proton = Proton::Project.new(project.dir) | ||
|
||
Proton::Server | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Class: Watcher (ProScribe) | ||
# Monitors files for changes. | ||
# | ||
# ## Common usage | ||
# | ||
# w = Watcher.new(project) { puts 'update' } | ||
# w.join | ||
# | ||
module ProScribe | ||
class Watcher | ||
def initialize(project, &blk) | ||
require 'fssm' | ||
|
||
@threads = Array.new | ||
|
||
# Monitor the project's manual | ||
@threads << Thread.new { | ||
monitor(project.config.manual) { |*a| project.make; yield *a } | ||
} | ||
|
||
# Monitor ProScribe's default theme | ||
@threads << Thread.new { | ||
monitor(ProScribe.root('data')) { |*a| project.make; yield *a } | ||
} | ||
|
||
# Monitor the project's files | ||
project.config.files.each do |group| | ||
threads << Thread.new { | ||
path = project.root(group.source) | ||
path = path.gsub(/\*.*$/, '') | ||
path = File.realpath(path) | ||
|
||
monitor(path) { |*a| project.make; yield *a } | ||
} | ||
end | ||
end | ||
|
||
# Attribute: threads (ProScribe::Watcher) | ||
# The threads. | ||
# | ||
attr_reader :threads | ||
|
||
# Method: join (ProScribe::Watcher) | ||
# Asks all threads to join. | ||
# | ||
def join | ||
threads.each { |t| t.join } | ||
end | ||
|
||
private | ||
def monitor(path, &blk) | ||
updated = lambda { |path, file| | ||
yield path, file | ||
} | ||
|
||
FSSM.monitor(path) do | ||
update(&updated) | ||
create(&updated) | ||
delete(&updated) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters