class TDiary::Style::EtdiarySection
Attributes
anchor_type[R]
bodies[R]
categories[R]
stripped_subtitle[R]
stripped_subtitle_to_html[R]
subtitle[R]
subtitle_to_html[R]
Public Class Methods
new( title, author = nil )
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 11 def initialize( title, author = nil ) @subtitle = title if @subtitle then if "" == @subtitle then @subtitle = nil @anchor_type = :P elsif "<>" == @subtitle then @subtitle = nil @anchor_type = :A elsif /^<>/ =~ @subtitle then @subtitle = @subtitle[2..-1] @anchor_type = :H4 else @anchor_type = :H3 end else @subtitle = nil @anchor_type = nil end @bodies = [] @categories = get_categories @stripped_subtitle = strip_subtitle end
Public Instance Methods
<<(string)
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 106 def << (string) @bodies << string end
body()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 81 def body if @bodies then @bodies.join('') else '' end end
body=(str)
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 63 def body=(str) @bodies = str.split(/\n/) end
body_to_html()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 89 def body_to_html if @bodies then r = '' in_p = false @bodies.join('').each_line("\n\n") do |p| if /\A</ !~ p then r << "<p>#{p.chomp}</p>\n" else r << p end end r else '' end end
categories=(categories)
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 67 def categories=(categories) @categories = categories cat_str = "" categories.each {|cat| cat_str << "[#{cat}]" } @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil @stripped_subtitle = strip_subtitle end
categorized_subtitle()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 140 def categorized_subtitle return "" unless @subtitle cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0] return @stripped_subtitle unless cat cat.gsub(/\[(.*?)\]/) do $1.split(/,/).collect do |c| %Q|<%= category_anchor("#{c}") %>| end.join end + @stripped_subtitle end
get_categories()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 131 def get_categories return [] unless @subtitle cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0] return [] unless cat cat.scan(/\[(.*?)\]/).collect do |c| c[0].split(/,/) end.flatten end
set_body( bodies )
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 77 def set_body( bodies ) @bodies = bodies end
strip_subtitle()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 151 def strip_subtitle return nil unless @subtitle @subtitle.sub(/^(\[(.*?)\])+\s*/,'') end
subtitle=(subtitle)
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 35 def subtitle=(subtitle) cat_str = "" @categories.each {|cat| cat_str << "[#{cat}]" } cat_str << " " unless cat_str.empty? @subtitle = subtitle if @subtitle then if "" == @subtitle then @subtitle = nil @anchor_type = :P elsif "<>" == @subtitle then @subtitle = nil @anchor_type = :A elsif /^<>/ =~ @subtitle then @subtitle = @subtitle[2..-1] @anchor_type = :H4 else @subtitle = cat_str + subtitle @anchor_type = :H3 end else @subtitle = nil @anchor_type = nil end @stripped_subtitle = strip_subtitle end
to_s()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 127 def to_s "subtitle=#{@subtitle}, body=#{body}" end
to_src()
click to toggle source
# File lib/tdiary/style/etdiary.rb, line 110 def to_src s = '' case @anchor_type when :A s << "<<<>>>\n" when :P s << "<<>>\n" when :H4 s << "[#{@author}]" if @author s << "<<<>" + @subtitle + ">>\n" when :H3 s << "[#{@author}]" if @author s << "<<" + @subtitle + ">>\n" end s + ( if "" != body then body else "\n" end ) end