Class: TDiary::Style::EtdiarySection
- Inherits:
-
Object
- Object
- TDiary::Style::EtdiarySection
- Defined in:
- lib/tdiary/style/etdiary.rb
Instance Attribute Summary collapse
-
#anchor_type ⇒ Object
readonly
Returns the value of attribute anchor_type.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#bodies ⇒ Object
readonly
Returns the value of attribute bodies.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#stripped_subtitle ⇒ Object
(also: #stripped_subtitle_to_html)
readonly
Returns the value of attribute stripped_subtitle.
-
#subtitle ⇒ Object
(also: #subtitle_to_html)
Returns the value of attribute subtitle.
Instance Method Summary collapse
- #<<(string) ⇒ Object
- #body ⇒ Object
- #body=(str) ⇒ Object
- #body_to_html ⇒ Object
- #categorized_subtitle ⇒ Object
- #get_categories ⇒ Object
-
#initialize(title, author = nil) ⇒ EtdiarySection
constructor
A new instance of EtdiarySection.
- #set_body(bodies) ⇒ Object
- #strip_subtitle ⇒ Object
- #to_s ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(title, author = nil) ⇒ EtdiarySection
Returns a new instance of EtdiarySection.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tdiary/style/etdiary.rb', line 12 def initialize( title, = 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 |
Instance Attribute Details
#anchor_type ⇒ Object (readonly)
Returns the value of attribute anchor_type.
6 7 8 |
# File 'lib/tdiary/style/etdiary.rb', line 6 def anchor_type @anchor_type end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
6 7 8 |
# File 'lib/tdiary/style/etdiary.rb', line 6 def @author end |
#bodies ⇒ Object (readonly)
Returns the value of attribute bodies.
6 7 8 |
# File 'lib/tdiary/style/etdiary.rb', line 6 def bodies @bodies end |
#categories ⇒ Object
Returns the value of attribute categories.
7 8 9 |
# File 'lib/tdiary/style/etdiary.rb', line 7 def categories @categories end |
#stripped_subtitle ⇒ Object (readonly) Also known as: stripped_subtitle_to_html
Returns the value of attribute stripped_subtitle.
7 8 9 |
# File 'lib/tdiary/style/etdiary.rb', line 7 def stripped_subtitle @stripped_subtitle end |
#subtitle ⇒ Object Also known as: subtitle_to_html
Returns the value of attribute subtitle.
6 7 8 |
# File 'lib/tdiary/style/etdiary.rb', line 6 def subtitle @subtitle end |
Instance Method Details
#<<(string) ⇒ Object
107 108 109 |
# File 'lib/tdiary/style/etdiary.rb', line 107 def << (string) @bodies << string end |
#body ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/tdiary/style/etdiary.rb', line 82 def body if @bodies then @bodies.join('') else '' end end |
#body=(str) ⇒ Object
64 65 66 |
# File 'lib/tdiary/style/etdiary.rb', line 64 def body=(str) @bodies = str.split(/\n/) end |
#body_to_html ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/tdiary/style/etdiary.rb', line 90 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 |
#categorized_subtitle ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/tdiary/style/etdiary.rb', line 141 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 ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/tdiary/style/etdiary.rb', line 132 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) ⇒ Object
78 79 80 |
# File 'lib/tdiary/style/etdiary.rb', line 78 def set_body( bodies ) @bodies = bodies end |
#strip_subtitle ⇒ Object
152 153 154 155 |
# File 'lib/tdiary/style/etdiary.rb', line 152 def strip_subtitle return nil unless @subtitle @subtitle.sub(/^(\[(.*?)\])+\s*/,'') end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/tdiary/style/etdiary.rb', line 128 def to_s "subtitle=#{@subtitle}, body=#{body}" end |
#to_src ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tdiary/style/etdiary.rb', line 111 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 |