-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See the README for more details.
- Loading branch information
Showing
9 changed files
with
486 additions
and
6 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
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,50 @@ | ||
|
||
require "erb" | ||
|
||
class EmptyBinding | ||
def self.create | ||
self.new.empty_binding | ||
end | ||
|
||
def empty_binding | ||
binding | ||
end | ||
end | ||
|
||
RUNDOC_ERB_BINDINGS = Hash.new {|h, k| h[k] = EmptyBinding.create } | ||
|
||
class Rundoc::CodeCommand | ||
class PrintERB < Rundoc::CodeCommand | ||
|
||
def initialize(line = nil, binding: "default") | ||
@line = line | ||
@binding = RUNDOC_ERB_BINDINGS[binding] | ||
end | ||
|
||
def to_md(env) | ||
if render_before? | ||
env[:before] << render | ||
end | ||
|
||
"" | ||
end | ||
|
||
def render | ||
@render ||= ERB.new([@line, contents].compact.join("\n")).result(@binding) | ||
end | ||
|
||
def call(erb={}) | ||
if render_before? | ||
"" | ||
else | ||
render | ||
end | ||
end | ||
|
||
def render_before? | ||
!render_command? && render_result? | ||
end | ||
end | ||
end | ||
|
||
Rundoc.register_code_command(:"print.erb", Rundoc::CodeCommand::PrintERB) |
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,33 @@ | ||
class Rundoc::CodeCommand | ||
class PrintText < Rundoc::CodeCommand | ||
def initialize(line) | ||
@line = line | ||
end | ||
|
||
def to_md(env) | ||
if render_before? | ||
env[:before] << [@line, contents].compact.join("\n") | ||
end | ||
|
||
"" | ||
end | ||
|
||
def hidden? | ||
!render_result? | ||
end | ||
|
||
def call(env = {}) | ||
if render_before? | ||
"" | ||
else | ||
[@line, contents].compact.join("\n") | ||
end | ||
end | ||
|
||
def render_before? | ||
!render_command? && render_result? | ||
end | ||
end | ||
end | ||
|
||
Rundoc.register_code_command(:"print.text", Rundoc::CodeCommand::PrintText) |
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
Oops, something went wrong.