Class: Liquidbook::CLI
- Inherits:
-
Thor
- Object
- Thor
- Liquidbook::CLI
- Defined in:
- lib/liquidbook/cli.rb
Instance Method Summary collapse
Instance Method Details
#render(template) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/liquidbook/cli.rb', line 61 def render(template) theme_root = File.([:root]) Liquidbook.root = theme_root renderer = ThemeRenderer.new(theme_root: theme_root) if template.start_with?("sections/") || template.start_with?("snippets/") dir, name = template.split("/", 2) name = name.sub(/\.liquid$/, "") html = dir == "sections" ? renderer.render_section(name) : renderer.render_snippet(name) else html = renderer.render_section(template.sub(/\.liquid$/, "")) end puts html rescue Liquidbook::Error => e warn "Error: #{e.}" exit 1 end |
#server ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/liquidbook/cli.rb', line 14 def server theme_root = File.([:root]) Liquidbook.root = theme_root pid_manager = PidManager.new(theme_root: theme_root) result = pid_manager.ensure_can_start! warn "Warning: Removed stale PID file." if result == :stale_pid_cleaned puts "Liquidbook v#{VERSION}" puts "Theme root: #{theme_root}" puts "Server: http://#{[:host]}:#{[:port]}" puts "" sections = Dir.glob(File.join(theme_root, "sections", "*.liquid")).size snippets = Dir.glob(File.join(theme_root, "snippets", "*.liquid")).size puts "Found #{sections} sections, #{snippets} snippets" puts "" pid_manager.write_pid at_exit { pid_manager.remove_pid } Server::App.set :port, [:port] Server::App.set :bind, [:host] Server::App.run! end |
#stop ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/liquidbook/cli.rb', line 42 def stop theme_root = File.([:root]) pid_manager = PidManager.new(theme_root: theme_root) case pid_manager.stop! when :stopped puts "Server stopped." when :not_running puts "Server is not running." when :stale_pid_cleaned puts "Server is not running (removed stale PID file)." end rescue Liquidbook::Error => e warn "Error: #{e.}" exit 1 end |
#version ⇒ Object
82 83 84 |
# File 'lib/liquidbook/cli.rb', line 82 def version puts "liquidbook #{VERSION}" end |