Class: SlideDown
- Inherits:
-
Object
- Object
- SlideDown
- Defined in:
- lib/slidedown.rb
Constant Summary collapse
- USAGE =
"The SlideDown command line interface takes a .md (Markdown) file as its only required argument. It will convert the file to HTML in standard out. Options: -t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags. This can also accept an absolute path for templates outside the /templates directory."
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .option_parser(source) ⇒ Object
- .render(source_path, template = "default") ⇒ Object
- .run!(argv = ARGV) ⇒ Object
Instance Method Summary collapse
-
#initialize(raw, opts = {}) ⇒ SlideDown
constructor
Ensures that the first slide has proper !SLIDE declaration.
- #read(path) ⇒ Object
- #render(name) ⇒ Object
- #slides ⇒ Object
Constructor Details
#initialize(raw, opts = {}) ⇒ SlideDown
Ensures that the first slide has proper !SLIDE declaration
49 50 51 52 53 54 55 |
# File 'lib/slidedown.rb', line 49 def initialize(raw, opts = {}) @raw = raw =~ /\A!SLIDE/ ? raw : "!SLIDE\n#{raw}" extract_classes! self.stylesheets = opts[:stylesheets] || local_stylesheets self.title = opts[:title] || "Slides" end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
15 16 17 |
# File 'lib/slidedown.rb', line 15 def classes @classes end |
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
14 15 16 |
# File 'lib/slidedown.rb', line 14 def stylesheets @stylesheets end |
#title ⇒ Object
Returns the value of attribute title.
14 15 16 |
# File 'lib/slidedown.rb', line 14 def title @title end |
Class Method Details
.option_parser(source) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/slidedown.rb', line 32 def self.option_parser(source) OptionParser.new do |opts| opts.on('-h', '--help') { puts USAGE } opts.on('-t', '--template TEMPLATE') do |template| render(source, template) end end end |
.render(source_path, template = "default") ⇒ Object
41 42 43 44 45 46 |
# File 'lib/slidedown.rb', line 41 def self.render(source_path, template = "default") if source_path = new(File.read(source_path)) puts .render(template) end end |
.run!(argv = ARGV) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/slidedown.rb', line 17 def self.run!(argv = ARGV) args = argv.dup if args.empty? puts USAGE else source = args[0] if args.length == 1 render(source) else option_parser(source).parse!(args) end end end |
Instance Method Details
#read(path) ⇒ Object
61 62 63 |
# File 'lib/slidedown.rb', line 61 def read(path) File.read(File.join(File.dirname(__FILE__), '..', "templates", path)) end |
#render(name) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/slidedown.rb', line 65 def render(name) if is_absolute_path?(name) template = File.read("#{name}.erb") else directory = File.join(File.dirname(__FILE__), "..", "templates") path = File.join(directory, "#{name}.erb") template = File.read(path) end ERB.new(template).result(binding) end |