Class: Agentilda::Viewer
- Inherits:
-
Object
- Object
- Agentilda::Viewer
- Defined in:
- lib/agentilda/viewer.rb
Overview
Hands Markdown files to a renderer outside this process: the system
viewer via open, or mdfried in the terminal.
Both paths shell out, so the class takes its two effects as lambdas and the specs assert on the commands instead of launching viewers on the box running the suite.
Constant Summary collapse
- INSTALL =
What to run when mdfried is asked for but not installed. Homebrew is the one package manager the toolchain already assumes (see the Brewfile convention), so there is no fallback chain to get wrong.
"brew install mdfried >/dev/null"- DETECT =
How to notice mdfried is missing without depending on
which, which differs across shells;command -vis POSIX. "command -v mdfried >/dev/null"
Instance Method Summary collapse
-
#initialize(launch: ->(*cmd) { system(*cmd) }, pipe: ->(cmd, &block) { IO.popen(cmd, "w", &block) }) ⇒ Viewer
constructor
A new instance of Viewer.
-
#mdfried(paths) ⇒ void
Streams each file's content into mdfried, installing it first when it is missing.
-
#open(paths) ⇒ void
Opens each file in whatever the system has configured for Markdown.
Constructor Details
#initialize(launch: ->(*cmd) { system(*cmd) }, pipe: ->(cmd, &block) { IO.popen(cmd, "w", &block) }) ⇒ Viewer
Returns a new instance of Viewer.
22 23 24 25 26 |
# File 'lib/agentilda/viewer.rb', line 22 def initialize(launch: ->(*cmd) { system(*cmd) }, pipe: ->(cmd, &block) { IO.popen(cmd, "w", &block) }) @launch = launch @pipe = pipe end |
Instance Method Details
#mdfried(paths) ⇒ void
This method returns an undefined value.
Streams each file's content into mdfried, installing it first when it is missing.
42 43 44 45 46 47 |
# File 'lib/agentilda/viewer.rb', line 42 def mdfried(paths) ensure_mdfried! Array(paths).each do |path| @pipe.call("mdfried") { |io| io.write(File.read(path)) } end end |
#open(paths) ⇒ void
This method returns an undefined value.
Opens each file in whatever the system has configured for Markdown.
32 33 34 |
# File 'lib/agentilda/viewer.rb', line 32 def open(paths) Array(paths).each { |path| @launch.call("open", path) } end |