Module: Softcover::Commands::Server
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#no_listener ⇒ Object
Returns the value of attribute no_listener.
Instance Method Summary collapse
-
#listen_for_changes ⇒ Object
Listens for changes to the book’s source files.
- #markdown? ⇒ Boolean
- #rebuild(modified = nil) ⇒ Object
- #run(port) ⇒ Object
- #start_server(port) ⇒ Object
Methods included from Utils
#add_highlight_class!, #as_size, #current_book, #digest, #executable, #execute, #in_book_directory?, #logged_in?, #mkdir, #path, #reset_current_book!, #rm, #silence, #source, #tmpify, #write_pygments_file
Methods included from Output
should_output?, silence!, silent?, #system, unsilence!
Instance Attribute Details
#no_listener ⇒ Object
Returns the value of attribute no_listener.
6 7 8 |
# File 'lib/softcover/commands/server.rb', line 6 def no_listener @no_listener end |
Instance Method Details
#listen_for_changes ⇒ Object
Listens for changes to the book’s source files.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/softcover/commands/server.rb', line 10 def listen_for_changes return if defined?(@no_listener) && @no_listener server_pid = Process.pid directories = ['.', 'chapters'] @listener = Listen.to(*directories) file_pattern = markdown? ? '\.md|\.txt' : '\.tex' @listener.filter(/(#{file_pattern}|custom\.sty)$/) @listener.change do |modified| rebuild modified.try(:first) Process.kill("HUP", server_pid) end @listener.start end |
#markdown? ⇒ Boolean
25 26 27 |
# File 'lib/softcover/commands/server.rb', line 25 def markdown? !Dir.glob(path('chapters/*.md')).empty? end |
#rebuild(modified = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/softcover/commands/server.rb', line 29 def rebuild(modified=nil) printf modified ? "=> #{File.basename modified} changed, rebuilding... " : 'Building...' t = Time.now builder = Softcover::Builders::Html.new builder.build(preserve_tex: true) puts "Done. (#{(Time.now - t).round(2)}s)" rescue Softcover::BookManifest::NotFound => e puts e. end |
#run(port) ⇒ Object
49 50 51 52 |
# File 'lib/softcover/commands/server.rb', line 49 def run(port) listen_for_changes start_server port end |