Class: Deck::Slide
- Inherits:
-
Erector::Widget
- Object
- Erector::Widget
- Deck::Slide
- Defined in:
- lib/deck/slide.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#markdown_text ⇒ Object
readonly
Returns the value of attribute markdown_text.
Class Method Summary collapse
-
.from_file(markdown_file) ⇒ Object
todo: test this method.
-
.split(content) ⇒ Object
given a chunk of Markdown text, splits it into an array of Slide objects.
Instance Method Summary collapse
- #<<(s) ⇒ Object
- #content ⇒ Object
- #empty? ⇒ Boolean
- #header_only? ⇒ Boolean
-
#initialize(options = {}) ⇒ Slide
constructor
A new instance of Slide.
- #markdown ⇒ Object
- #massaged_markdown_text ⇒ Object
- #process_classes ⇒ Object
- #slide_id ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Slide
Returns a new instance of Slide.
49 50 51 52 53 54 |
# File 'lib/deck/slide.rb', line 49 def initialize = {} super @classes = process_classes @markdown_text = "" end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
44 45 46 |
# File 'lib/deck/slide.rb', line 44 def classes @classes end |
#markdown_text ⇒ Object (readonly)
Returns the value of attribute markdown_text.
44 45 46 |
# File 'lib/deck/slide.rb', line 44 def markdown_text @markdown_text end |
Class Method Details
.from_file(markdown_file) ⇒ Object
todo: test this method
9 10 11 |
# File 'lib/deck/slide.rb', line 9 def self.from_file markdown_file split File.read(markdown_file) end |
.split(content) ⇒ Object
given a chunk of Markdown text, splits it into an array of Slide objects
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 39 40 |
# File 'lib/deck/slide.rb', line 14 def self.split content unless content =~ /^\<?!SLIDE/m content = content.gsub(/^# /m, "<!SLIDE>\n# ") end lines = content.split("\n") = [] << ( = Slide.new) until lines.empty? line = lines.shift if line =~ /^<?!SLIDE(.*)>?/ << ( = Slide.new(:classes => $1)) elsif line =~ /^# / and !.empty? # every H1 defines a new slide, unless there's a !SLIDE before it << ( = Slide.new) << line else << line end end .delete_if {|| .empty? } end |
Instance Method Details
#<<(s) ⇒ Object
83 84 85 86 |
# File 'lib/deck/slide.rb', line 83 def <<(s) @markdown_text << s @markdown_text << "\n" end |
#content ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/deck/slide.rb', line 112 def content section :class => @classes, :id => do text "\n" # markdown HTML should be left-aligned, in case of PRE blocks and other quirks html = markdown.render(massaged_markdown_text) rawtext html end end |
#empty? ⇒ Boolean
88 89 90 |
# File 'lib/deck/slide.rb', line 88 def empty? @markdown_text.strip == "" end |
#header_only? ⇒ Boolean
100 101 102 |
# File 'lib/deck/slide.rb', line 100 def header_only? markdown_text.strip =~ /^# / and markdown_text.strip.split("\n").size == 1 end |
#markdown ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/deck/slide.rb', line 69 def markdown @@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :no_intra_emphasis => true, :tables => true, :fenced_code_blocks => true, :no_intra_emphasis => true, :autolink => true, :strikethrough => true, :lax_html_blocks => false, :space_after_headers => true, :superscript => false ) end |
#massaged_markdown_text ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/deck/slide.rb', line 104 def massaged_markdown_text unless header_only? "##{markdown_text.strip}" else markdown_text end end |
#process_classes ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/deck/slide.rb', line 56 def process_classes ["slide"] + case @classes when NilClass [] when String @classes.strip.chomp('>').split when Array @classes else raise "can't deal with :classes => #{@classes.inspect}" end end |
#slide_id ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/deck/slide.rb', line 92 def @slide_id ||= begin lines = @markdown_text.split("\n") raise "an empty slide has no id" if lines.empty? lines.first.gsub(/^#*/, '').strip.downcase.gsub(/[^\w\s]/, '').gsub(/\s/, '_') end end |