Add class Repubmark::Elems::CustomLogue
This commit is contained in:
parent
c901f4070e
commit
a786c6d123
|
@ -17,6 +17,7 @@ require_relative 'repubmark/elems/article'
|
||||||
|
|
||||||
# Always inside Article
|
# Always inside Article
|
||||||
require_relative 'repubmark/elems/annotation'
|
require_relative 'repubmark/elems/annotation'
|
||||||
|
require_relative 'repubmark/elems/custom_logue'
|
||||||
# Always inside Article, Chapter
|
# Always inside Article, Chapter
|
||||||
require_relative 'repubmark/elems/chapter'
|
require_relative 'repubmark/elems/chapter'
|
||||||
# Always inside Annotation, Blockquote, Chapter
|
# Always inside Annotation, Blockquote, Chapter
|
||||||
|
|
|
@ -21,15 +21,19 @@ module Repubmark
|
||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
[
|
[
|
||||||
|
@prologue&.to_html,
|
||||||
@annotation&.to_html,
|
@annotation&.to_html,
|
||||||
@chapter&.to_html,
|
@chapter&.to_html,
|
||||||
|
@epilogue&.to_html,
|
||||||
].compact.join.freeze
|
].compact.join.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_gemtext
|
def to_gemtext
|
||||||
[
|
[
|
||||||
|
@prologue&.to_gemtext,
|
||||||
@annotation&.to_gemtext,
|
@annotation&.to_gemtext,
|
||||||
@chapter&.to_gemtext,
|
@chapter&.to_gemtext,
|
||||||
|
@epilogue&.to_gemtext,
|
||||||
].compact.join("\n\n\n").freeze
|
].compact.join("\n\n\n").freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,9 +41,21 @@ module Repubmark
|
||||||
# Builder methods #
|
# Builder methods #
|
||||||
###################
|
###################
|
||||||
|
|
||||||
|
def prologue
|
||||||
|
raise 'Prologue already exists' if @prologue
|
||||||
|
raise 'Prologue after annotation' if @annotation
|
||||||
|
raise 'Prologue after chapters' if @chapters
|
||||||
|
raise 'Prologue after epilogue' if @epilogue
|
||||||
|
|
||||||
|
@prologue = CustomBlock.new self
|
||||||
|
yield @prologue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def annotation
|
def annotation
|
||||||
raise 'Annotation already exists' if @annotation
|
raise 'Annotation already exists' if @annotation
|
||||||
raise 'Annotation after chapter' if @chapter
|
raise 'Annotation after chapters' if @chapter
|
||||||
|
raise 'Annotation after epilogue' if @epilogue
|
||||||
|
|
||||||
@annotation = Annotation.new self
|
@annotation = Annotation.new self
|
||||||
yield @annotation
|
yield @annotation
|
||||||
|
@ -52,6 +68,8 @@ module Repubmark
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method_name, ...)
|
def method_missing(method_name, ...)
|
||||||
|
raise 'Chapters after chapters' if @epilogue
|
||||||
|
|
||||||
chapter = @chapter || Chapter.new(self)
|
chapter = @chapter || Chapter.new(self)
|
||||||
if chapter.respond_to? method_name
|
if chapter.respond_to? method_name
|
||||||
@chapter = chapter
|
@chapter = chapter
|
||||||
|
@ -61,6 +79,14 @@ module Repubmark
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def epilogue
|
||||||
|
raise 'Epilogue already exists' if @epilogue
|
||||||
|
|
||||||
|
@epilogue = CustomBlock.new self
|
||||||
|
yield @epilogue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def config=(config)
|
def config=(config)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Repubmark
|
||||||
|
module Elems
|
||||||
|
class CustomLogue < Base
|
||||||
|
FORMATS = %i[html gemtext].freeze
|
||||||
|
|
||||||
|
parents :Canvas
|
||||||
|
|
||||||
|
def initialize(parent)
|
||||||
|
super parent
|
||||||
|
@for = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
#################
|
||||||
|
# Basic methods #
|
||||||
|
#################
|
||||||
|
|
||||||
|
def to_html
|
||||||
|
"<div>\n#{@for[:html].strip}\n</div>\n".freeze if @for[:html]
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_gemtext
|
||||||
|
"#{@for[:gemtext].strip}\n".freeze if @for[:gemtext]
|
||||||
|
end
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Builder methods #
|
||||||
|
###################
|
||||||
|
|
||||||
|
def for(format, str)
|
||||||
|
raise 'Invalid format' unless FORMATS.include? format
|
||||||
|
raise 'Format already configured' if @for.key? format
|
||||||
|
|
||||||
|
str = String(str).strip.freeze
|
||||||
|
return if str.empty?
|
||||||
|
|
||||||
|
@for[format] = str
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue