Add format "summary_plain"
This commit is contained in:
parent
8ec0774613
commit
9a7f8bac53
24 changed files with 102 additions and 16 deletions
|
@ -24,6 +24,9 @@ css_classes: &css_classes
|
|||
word_count:
|
||||
format: word_count
|
||||
|
||||
summary_plain:
|
||||
format: summary_plain
|
||||
|
||||
gemini:
|
||||
<<: *paths
|
||||
format: gemtext
|
||||
|
|
2
examples/full.summary.txt
Normal file
2
examples/full.summary.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
Annotation paragraph text Chapter 1 Chapter 1 paragraph text Chapter 2
|
||||
Chapter 2 paragraph text
|
1
examples/hello.summary.txt
Normal file
1
examples/hello.summary.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Hello, World!
|
|
@ -19,11 +19,22 @@ context = BasicObject.new
|
|||
def context.article = $article
|
||||
context.instance_eval template, __FILE__, __LINE__
|
||||
|
||||
def wrap(str)
|
||||
words = str.strip.split
|
||||
lines = [[]]
|
||||
words.each do |word|
|
||||
lines << [] if [*lines.last, word].join(' ').length > 70
|
||||
lines.last << word
|
||||
end
|
||||
lines.map { |line| "#{line.join(' ')}\n" }.join.freeze
|
||||
end
|
||||
|
||||
output =
|
||||
case config.format
|
||||
when :word_count then $article.word_count
|
||||
when :html then $article.to_html
|
||||
when :gemtext then $article.to_gemtext
|
||||
when :word_count then $article.word_count
|
||||
when :summary_plain then wrap $article.to_summary_plain
|
||||
when :html then $article.to_html
|
||||
when :gemtext then $article.to_gemtext
|
||||
end.to_s.strip
|
||||
|
||||
puts output unless output.empty?
|
||||
|
|
|
@ -57,5 +57,5 @@ require_relative 'repubmark/elems/text'
|
|||
require_relative 'repubmark/elems/link'
|
||||
|
||||
module Repubmark
|
||||
FORMATS = %i[gemtext html word_count].freeze
|
||||
FORMATS = %i[gemtext html summary_plain word_count].freeze
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@ module Repubmark
|
|||
|
||||
def word_count = 1
|
||||
|
||||
def to_summary_plain = abbrev
|
||||
|
||||
def to_html
|
||||
%(<abbr title="#{escape_transcript}">#{escape_abbrev}</abbr>).freeze
|
||||
end
|
||||
|
|
|
@ -16,6 +16,8 @@ module Repubmark
|
|||
|
||||
def word_count = @canvas.word_count
|
||||
|
||||
def to_summary_plain = @canvas.to_summary_plain
|
||||
|
||||
def to_html
|
||||
[
|
||||
%(<div#{html_class(:annotation)}>\n),
|
||||
|
|
|
@ -19,6 +19,13 @@ module Repubmark
|
|||
(@chapter&.word_count || 0)
|
||||
end
|
||||
|
||||
def to_summary_plain
|
||||
[
|
||||
@annotation&.to_summary_plain,
|
||||
@chapter&.to_summary_plain,
|
||||
].compact.join(' ').freeze
|
||||
end
|
||||
|
||||
def to_html
|
||||
[
|
||||
@prologue&.to_html,
|
||||
|
|
|
@ -15,6 +15,8 @@ module Repubmark
|
|||
|
||||
def word_count = 0
|
||||
|
||||
def to_summary_plain = nil
|
||||
|
||||
def to_html
|
||||
raise NotImplementedError, "#{self.class}#to_html"
|
||||
end
|
||||
|
|
|
@ -16,9 +16,19 @@ module Repubmark
|
|||
|
||||
def word_count = @items.sum(&:word_count)
|
||||
|
||||
def to_html = @items.map(&:to_html).join.freeze
|
||||
def to_summary_plain
|
||||
return if @items.empty?
|
||||
|
||||
def to_gemtext = @items.map(&:to_gemtext).join("\n").freeze
|
||||
@items.filter_map(&:to_summary_plain).join(' ').freeze
|
||||
end
|
||||
|
||||
def to_html
|
||||
@items.map(&:to_html).join.freeze unless @items.empty?
|
||||
end
|
||||
|
||||
def to_gemtext
|
||||
@items.map(&:to_gemtext).join("\n").freeze unless @items.empty?
|
||||
end
|
||||
|
||||
###################
|
||||
# Builder methods #
|
||||
|
|
|
@ -18,7 +18,13 @@ module Repubmark
|
|||
|
||||
def word_count = @items.sum(&:word_count)
|
||||
|
||||
def to_summary_plain
|
||||
@items.map(&:to_summary_plain).join(' ').freeze unless @items.empty?
|
||||
end
|
||||
|
||||
def to_html
|
||||
return if @items.empty?
|
||||
|
||||
[
|
||||
'<span>',
|
||||
*@items.map(&:to_html),
|
||||
|
@ -26,7 +32,9 @@ module Repubmark
|
|||
].map { |s| "#{s}\n" }.join.freeze
|
||||
end
|
||||
|
||||
def to_gemtext = @items.map(&:to_gemtext).join(' ').strip.freeze
|
||||
def to_gemtext
|
||||
@items.map(&:to_gemtext).join(' ').strip.freeze unless @items.empty?
|
||||
end
|
||||
|
||||
##################
|
||||
# Helper methods #
|
||||
|
|
|
@ -25,6 +25,16 @@ module Repubmark
|
|||
@chapters.sum(&:word_count)
|
||||
end
|
||||
|
||||
def to_summary_plain
|
||||
str = [
|
||||
@title,
|
||||
@canvas.to_summary_plain,
|
||||
*@chapters.map(&:to_summary_plain),
|
||||
].compact.join(' ').strip.freeze
|
||||
|
||||
str.empty? ? nil : str
|
||||
end
|
||||
|
||||
def to_html
|
||||
[
|
||||
build_title_html,
|
||||
|
@ -78,7 +88,7 @@ module Repubmark
|
|||
def title=(title)
|
||||
return @title = nil if title.nil?
|
||||
|
||||
title = String(title).strip.freeze
|
||||
title = String(title).split.join(' ').strip.freeze
|
||||
raise 'Empty title' if title.empty?
|
||||
|
||||
@title = title
|
||||
|
|
|
@ -14,9 +14,11 @@ module Repubmark
|
|||
# Basic methods #
|
||||
#################
|
||||
|
||||
def to_summary_plain = "«#@str»".freeze
|
||||
|
||||
def to_html = "<code>#{CGI.escape_html(@str)}</code>".freeze
|
||||
|
||||
def to_gemtext = "«#{@str}»".freeze
|
||||
def to_gemtext = "«#@str»".freeze
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module Repubmark
|
|||
end
|
||||
|
||||
def to_gemtext
|
||||
caption = @caption.to_gemtext
|
||||
caption = @caption.to_gemtext.to_s.strip
|
||||
caption = @alt if caption.empty?
|
||||
"=> #{src} #{caption}\n".freeze
|
||||
end
|
||||
|
|
|
@ -21,11 +21,13 @@ module Repubmark
|
|||
|
||||
def word_count = 1
|
||||
|
||||
def to_summary_plain = "#@top/#@bottom".freeze
|
||||
|
||||
def to_html
|
||||
"<sup>#@top</sup>⁄<sub>#@bottom</sub>".freeze
|
||||
end
|
||||
|
||||
def to_gemtext = "#@top/#@bottom"
|
||||
def to_gemtext = "#@top/#@bottom".freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,8 @@ module Repubmark
|
|||
|
||||
def word_count = components.sum(&:word_count)
|
||||
|
||||
def to_summary_plain = components.map(&:to_summary_plain).join.freeze
|
||||
|
||||
def to_html = components.map(&:to_html).join.freeze
|
||||
|
||||
def to_gemtext = components.map(&:to_gemtext).join.freeze
|
||||
|
|
|
@ -20,6 +20,8 @@ module Repubmark
|
|||
|
||||
def word_count = @items.sum(&:word_count)
|
||||
|
||||
def to_summary_plain = @items.map(&:to_summary_plain).join(' ').freeze
|
||||
|
||||
def to_html
|
||||
[
|
||||
"<#{tag_name}>\n",
|
||||
|
@ -28,7 +30,7 @@ module Repubmark
|
|||
].join.freeze
|
||||
end
|
||||
|
||||
def to_gemtext = @items.map(&:to_gemtext).join
|
||||
def to_gemtext = @items.map(&:to_gemtext).join.freeze
|
||||
|
||||
##################
|
||||
# Helper methods #
|
||||
|
|
|
@ -25,6 +25,13 @@ module Repubmark
|
|||
|
||||
def word_count = @caption.word_count + (@sublist&.word_count || 0)
|
||||
|
||||
def to_summary_plain
|
||||
[
|
||||
@caption.to_summary_plain,
|
||||
@sublist&.to_summary_plain,
|
||||
].compact.join("\n").freeze
|
||||
end
|
||||
|
||||
def to_html
|
||||
[
|
||||
"<li>\n",
|
||||
|
|
|
@ -16,6 +16,8 @@ module Repubmark
|
|||
|
||||
def word_count = @caption.word_count
|
||||
|
||||
def to_summary_plain = @caption.to_summary_plain
|
||||
|
||||
def to_html = "<p>\n#{@caption.to_html}</p>\n".freeze
|
||||
|
||||
def to_gemtext = "#{@caption.to_gemtext}\n".freeze
|
||||
|
|
|
@ -18,6 +18,10 @@ module Repubmark
|
|||
|
||||
def word_count = @items.sum(&:word_count)
|
||||
|
||||
def to_summary_plain
|
||||
"«#{@items.map(&:to_summary_plain).join(' ')}»".freeze
|
||||
end
|
||||
|
||||
def to_html = "«#{@items.map(&:to_html).join("\n")}»".freeze
|
||||
|
||||
def to_gemtext = "«#{@items.map(&:to_gemtext).join(' ')}»".freeze
|
||||
|
|
|
@ -6,7 +6,7 @@ module Repubmark
|
|||
parents :Joint
|
||||
|
||||
SECT_HTML = '§'
|
||||
SECT_GEMTEXT = '§'
|
||||
SECT_UNICODE = '§'
|
||||
|
||||
attr_reader :count, :text
|
||||
|
||||
|
@ -30,9 +30,11 @@ module Repubmark
|
|||
|
||||
def word_count = count_words @text
|
||||
|
||||
def to_summary_plain = "#{SECT_UNICODE * count}#{text}".freeze
|
||||
|
||||
def to_html = "#{SECT_HTML * count}#{text}".freeze
|
||||
|
||||
def to_gemtext = "#{SECT_GEMTEXT * count}#{text}".freeze
|
||||
def to_gemtext = "#{SECT_UNICODE * count}#{text}".freeze
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Repubmark
|
|||
mdash: '—',
|
||||
}.freeze
|
||||
|
||||
GEMTEXT = {
|
||||
UNICODE = {
|
||||
ellipsis: '…',
|
||||
mdash: '—',
|
||||
}.freeze
|
||||
|
@ -27,9 +27,11 @@ module Repubmark
|
|||
# Basic methods #
|
||||
#################
|
||||
|
||||
def to_summary_plain = UNICODE.fetch @name
|
||||
|
||||
def to_html = HTML.fetch @name
|
||||
|
||||
def to_gemtext = GEMTEXT.fetch @name
|
||||
def to_gemtext = UNICODE.fetch @name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,8 @@ module Repubmark
|
|||
|
||||
def word_count = count_words @str
|
||||
|
||||
def to_summary_plain = @str
|
||||
|
||||
def to_html = str_to_html
|
||||
|
||||
def to_gemtext = @str
|
||||
|
|
1
test.rb
1
test.rb
|
@ -9,6 +9,7 @@ EXAMPLES_GLOB = File.expand_path('examples/*.repub', __dir__).freeze
|
|||
CONFIG = File.expand_path('examples/config.yml', __dir__).freeze
|
||||
|
||||
PROFILES = [
|
||||
%w[summary_plain summary.txt],
|
||||
%w[http html],
|
||||
%w[gemini gmi],
|
||||
].map(&:freeze).freeze
|
||||
|
|
Loading…
Reference in a new issue