Class: TDiary::Style::TdiarySection
- Inherits:
-
Object
- Object
- TDiary::Style::TdiarySection
- Defined in:
- lib/tdiary/style/tdiary.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#body ⇒ Object
Returns the value of attribute body.
-
#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
- #body_to_html ⇒ Object
- #categorized_subtitle ⇒ Object
-
#initialize(fragment, author = nil) ⇒ TdiarySection
constructor
A new instance of TdiarySection.
- #to_s ⇒ Object
- #to_src ⇒ Object
Constructor Details
#initialize(fragment, author = nil) ⇒ TdiarySection
Returns a new instance of TdiarySection.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tdiary/style/tdiary.rb', line 20 def initialize( fragment, = nil ) @author = lines = fragment.split( /\n+/ ) if lines.size > 1 then if /^<</ =~ lines[0] @subtitle = lines.shift.chomp.sub( /^</, '' ) elsif /^[ <]/u !~ lines[0] @subtitle = lines.shift.chomp end end @body = lines.join( "\n" ) @categories = get_categories @stripped_subtitle = strip_subtitle end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
14 15 16 |
# File 'lib/tdiary/style/tdiary.rb', line 14 def @author end |
#body ⇒ Object
Returns the value of attribute body.
14 15 16 |
# File 'lib/tdiary/style/tdiary.rb', line 14 def body @body end |
#categories ⇒ Object
Returns the value of attribute categories.
15 16 17 |
# File 'lib/tdiary/style/tdiary.rb', line 15 def categories @categories end |
#stripped_subtitle ⇒ Object (readonly) Also known as: stripped_subtitle_to_html
Returns the value of attribute stripped_subtitle.
15 16 17 |
# File 'lib/tdiary/style/tdiary.rb', line 15 def stripped_subtitle @stripped_subtitle end |
#subtitle ⇒ Object Also known as: subtitle_to_html
Returns the value of attribute subtitle.
14 15 16 |
# File 'lib/tdiary/style/tdiary.rb', line 14 def subtitle @subtitle end |
Instance Method Details
#body_to_html ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tdiary/style/tdiary.rb', line 79 def body_to_html html = "" @body.lines.each do |p| if p[0] == ?< then html = @body.dup break end html << "<p>#{p}</p>" end html end |
#categorized_subtitle ⇒ Object
95 96 97 98 99 |
# File 'lib/tdiary/style/tdiary.rb', line 95 def categorized_subtitle @categories.collect do |c| %Q|<%= category_anchor("#{c}") %>| end.join + @stripped_subtitle.to_s end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/tdiary/style/tdiary.rb', line 91 def to_s "subtitle=#{@subtitle}, body=#{@body}" end |
#to_src ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tdiary/style/tdiary.rb', line 61 def to_src s = '' if @stripped_subtitle then s += "[#{@author}]" if @author cat_str = "" @categories.each {|cat| cat_str << "[#{cat}]" } cat_str << " " unless cat_str.empty? s += cat_str s += '<' if /^</=~@subtitle s += @stripped_subtitle + "\n" else #s += ' ' unless @body =~ /\A\s</ end "#{s}#{@body}\n\n" end |