Skip to content

Commit

Permalink
Added subtitle partitioning (fixes #70)
Browse files Browse the repository at this point in the history
Code taken from Bespoke converter with minor changes
  • Loading branch information
obilodeau committed Sep 18, 2016
1 parent a2bd42c commit fb6e8fb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
6 changes: 5 additions & 1 deletion templates/slim/document.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ html lang=(attr :lang, 'en' unless attr? :nolang)
data-background-repeat=(attr 'title-slide-background-repeat')
data-background-position=(attr 'title-slide-background-position')
data-background-transition=(attr 'title-slide-background-transition'))
h1=@header.title
- if (_title_obj = doctitle partition: true, use_fallback: true).subtitle?
h1=slice_text _title_obj.title, (_slice = header.option? :slice)
h2=slice_text _title_obj.subtitle, _slice
- else
h1=@header.title
- preamble = @document.find_by context: :preamble
- unless preamble.nil? or preamble.length == 0
=preamble.pop.content
Expand Down
55 changes: 48 additions & 7 deletions templates/slim/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,52 @@
fail 'asciidoctor: FAILED: reveal.js backend needs Slim >= 2.1.0!'
end

# Add custom functions to this module that you want to use in your Slim
# templates. Within the template you must namespace the function
# (unless someone can show me how to include them in the evaluation context).
# You can change the namespace to whatever you want.
module Helpers
#def self.a_helper_function
#end
# This module gets mixed in to every node (the context of the template) at the
# time the node is being converted. The properties and methods in this module
# effectively become direct members of the template.
module Slim::Helpers

# Following constants from Bespoke back-end
#--
EOL = %(\n)
SliceHintRx = / +/
#--

# Following functions are taken from Bespoke back-end
#--
def pluck selector = {}, &block
quantity = (selector.delete :quantity).to_i
if blocks?
unless (result = find_by selector, &block).empty?
result = result[0..(quantity - 1)] if quantity > 0
result.each {|b| b.set_attr 'skip-option', '' }
end
else
result = []
end
quantity == 1 ? result[0] : result
end

def pluck_first selector = {}, &block
pluck selector.merge(quantity: 1), &block
end

def partition_title str
::Asciidoctor::Document::Title.new str, separator: (@document.attr 'title-separator')
end

# QUESTION should we wrap in span.line if active but delimiter is not present?
# TODO alternate terms for "slice" - part(ition), chunk, segment, split, break
def slice_text str, active = nil
if (active || (active.nil? && (option? :slice))) && (str.include? ' ')
(str.split SliceHintRx).map {|line| %(<span class="line">#{line}</span>) }.join EOL
else
str
end
end
#--
end

# More custom functions can be added in another namespace if required
#module Helpers
#end
6 changes: 6 additions & 0 deletions test/title-preamble.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
= Presentation Title
Author Name

Preamble

== Slide 2
3 changes: 3 additions & 0 deletions test/title-subtitle-partitioning.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= Catch phrase: Longer more explicit title introducing the real concept

== Slide 2

0 comments on commit fb6e8fb

Please sign in to comment.