tdiary-style-etdiary 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1e5c734840d8b63118f77b1a3dde0325ba55288
4
+ data.tar.gz: 851b335d20b388b09907c4f3f7b442f4ae2b9bd1
5
+ SHA512:
6
+ metadata.gz: c97e037290213ae43206b6ee6b12c4dec9e57a2dcb2f841e74974f4d396e3ea45f873500923ae11919a33484f1d14b149409d7c838f69cad27e2d9578b2dd8ef
7
+ data.tar.gz: fbf2e1dd1c3a1be5b978c0e8170fb19b6d165f7b52bb83369f12d10122d8a909cdab681281ca39ee89cb804e50449d8321c8e535a0d23c7b12f1adfd5fd5752b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tdiary-style-etdiary.gemspec
4
+ gemspec
5
+
6
+ gem 'tdiary', github: 'tdiary/tdiary-core'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 SHIBATA Hiroshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Tdiary::Style::Etdiary
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tdiary-style-etdiary'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tdiary-style-etdiary
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,448 @@
1
+ # -*- coding: utf-8; -*-
2
+ #
3
+ # etdiary_style.rb: tDiary style class for etDiary format.
4
+ # $Id: etdiary_style.rb,v 1.20 2008-03-02 09:01:20 kazuhiko Exp $
5
+ #
6
+ # if you want to use this style, add @style into tdiary.conf below:
7
+ #
8
+ # @style = 'etDiary'
9
+ #
10
+ module TDiary
11
+ module Style
12
+ class EtdiarySection
13
+ attr_reader :subtitle, :bodies, :author, :anchor_type
14
+ attr_reader :categories, :stripped_subtitle
15
+
16
+ alias :subtitle_to_html :subtitle
17
+ alias :stripped_subtitle_to_html :stripped_subtitle
18
+
19
+ def initialize( title, author = nil )
20
+ @subtitle = title
21
+ if @subtitle then
22
+ if "" == @subtitle then
23
+ @subtitle = nil
24
+ @anchor_type = :P
25
+ elsif "<>" == @subtitle then
26
+ @subtitle = nil
27
+ @anchor_type = :A
28
+ elsif /^<>/ =~ @subtitle then
29
+ @subtitle = @subtitle[2..-1]
30
+ @anchor_type = :H4
31
+ else
32
+ @anchor_type = :H3
33
+ end
34
+ else
35
+ @subtitle = nil
36
+ @anchor_type = nil
37
+ end
38
+ @bodies = []
39
+ @categories = get_categories
40
+ @stripped_subtitle = strip_subtitle
41
+ end
42
+
43
+ def subtitle=(subtitle)
44
+ cat_str = ""
45
+ @categories.each {|cat|
46
+ cat_str << "[#{cat}]"
47
+ }
48
+ cat_str << " " unless cat_str.empty?
49
+ @subtitle = subtitle
50
+ if @subtitle then
51
+ if "" == @subtitle then
52
+ @subtitle = nil
53
+ @anchor_type = :P
54
+ elsif "<>" == @subtitle then
55
+ @subtitle = nil
56
+ @anchor_type = :A
57
+ elsif /^<>/ =~ @subtitle then
58
+ @subtitle = @subtitle[2..-1]
59
+ @anchor_type = :H4
60
+ else
61
+ @subtitle = cat_str + subtitle
62
+ @anchor_type = :H3
63
+ end
64
+ else
65
+ @subtitle = nil
66
+ @anchor_type = nil
67
+ end
68
+ @stripped_subtitle = strip_subtitle
69
+ end
70
+
71
+ def body=(str)
72
+ @bodies = str.split(/\n/)
73
+ end
74
+
75
+ def categories=(categories)
76
+ @categories = categories
77
+ cat_str = ""
78
+ categories.each {|cat|
79
+ cat_str << "[#{cat}]"
80
+ }
81
+ @subtitle = @subtitle ? (cat_str + @stripped_subtitle) : nil
82
+ @stripped_subtitle = strip_subtitle
83
+ end
84
+
85
+ def set_body( bodies )
86
+ @bodies = bodies
87
+ end
88
+
89
+ def body
90
+ if @bodies then
91
+ @bodies.join('')
92
+ else
93
+ ''
94
+ end
95
+ end
96
+
97
+ def body_to_html
98
+ if @bodies then
99
+ r = ''
100
+ in_p = false
101
+ @bodies.join('').each_line("\n\n") do |p|
102
+ if /\A</ !~ p then
103
+ r << "<p>#{p.chomp}</p>\n"
104
+ else
105
+ r << p
106
+ end
107
+ end
108
+ r
109
+ else
110
+ ''
111
+ end
112
+ end
113
+
114
+ def << (string)
115
+ @bodies << string
116
+ end
117
+
118
+ def to_src
119
+ s = ''
120
+ case @anchor_type
121
+ when :A
122
+ s << "<<<>>>\n"
123
+ when :P
124
+ s << "<<>>\n"
125
+ when :H4
126
+ s << "[#{@author}]" if @author
127
+ s << "<<<>" + @subtitle + ">>\n"
128
+ when :H3
129
+ s << "[#{@author}]" if @author
130
+ s << "<<" + @subtitle + ">>\n"
131
+ end
132
+ s + ( if "" != body then body else "\n" end )
133
+ end
134
+
135
+ def to_s
136
+ "subtitle=#{@subtitle}, body=#{body}"
137
+ end
138
+
139
+ def get_categories
140
+ return [] unless @subtitle
141
+ cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
142
+ return [] unless cat
143
+ cat.scan(/\[(.*?)\]/).collect do |c|
144
+ c[0].split(/,/)
145
+ end.flatten
146
+ end
147
+
148
+ def categorized_subtitle
149
+ return "" unless @subtitle
150
+ cat = /^(\[(.*?)\])+/.match(@subtitle).to_a[0]
151
+ return @stripped_subtitle unless cat
152
+ cat.gsub(/\[(.*?)\]/) do
153
+ $1.split(/,/).collect do |c|
154
+ %Q|<%= category_anchor("#{c}") %>|
155
+ end.join
156
+ end + @stripped_subtitle
157
+ end
158
+
159
+ def strip_subtitle
160
+ return nil unless @subtitle
161
+ @subtitle.sub(/^(\[(.*?)\])+\s*/,'')
162
+ end
163
+ end
164
+
165
+ class EtHtml4Factory
166
+ def initialize( opt, idx = 1 )
167
+ @opt = opt
168
+ @idx = idx
169
+ end
170
+ def title( date, fragment )
171
+ return nil if nil == fragment.anchor_type
172
+ name = 'p%02d' % @idx
173
+ @idx += 1
174
+ if :A == fragment.anchor_type then
175
+ if @opt['anchor'] then
176
+ return "<a name=\"#{name}\"></a>"
177
+ else
178
+ return nil
179
+ end
180
+ end
181
+
182
+ r = ''
183
+ if @opt['index']
184
+ if fragment.subtitle
185
+ r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
186
+ else
187
+ r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
188
+ end
189
+ end
190
+
191
+ case fragment.anchor_type
192
+ when :P
193
+ r
194
+ when :H4
195
+ "<h4>" + r + ":</h4>\n"
196
+ when :H3
197
+ "<h3>" + r + "</h3>\n"
198
+ end
199
+ end
200
+ def section_start( date )
201
+ %Q[<div class="section">\n<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n]
202
+ end
203
+ def section_end( date )
204
+ "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n</div>\n"
205
+ end
206
+ def block_title?( fragment )
207
+ case fragment.anchor_type
208
+ when :H3, :H4
209
+ true
210
+ else
211
+ false
212
+ end
213
+ end
214
+ def p_start
215
+ "<p>"
216
+ end
217
+ def p_end
218
+ "</p>"
219
+ end
220
+ def pre_start
221
+ "<pre>"
222
+ end
223
+ def pre_end
224
+ "</pre>"
225
+ end
226
+ end
227
+
228
+ class EtCHtmlFactory
229
+ def initialize( opt, idx = 1 )
230
+ @opt = opt
231
+ @idx = idx
232
+ end
233
+ def title( date, fragment )
234
+ return nil if nil == fragment.anchor_type
235
+ name = 'p%02d' % @idx
236
+ return "<A NAME=\"#{name}\"></A>" if :A == fragment.anchor_type
237
+ r = ""
238
+ if fragment.subtitle
239
+ r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), #{fragment.subtitle.dump.gsub( /%/, '\\\\045' )} ) %>]
240
+ else
241
+ r << %Q[<%= subtitle_proc( Time::at( #{date.to_i} ), nil ) %>]
242
+ end
243
+ @idx += 1
244
+ case fragment.anchor_type
245
+ when :P
246
+ r
247
+ when :H4
248
+ r + ": "
249
+ when :H3
250
+ "<H3>" + r + "</H3>\n"
251
+ end
252
+ end
253
+ def section_start( date )
254
+ "<%=section_enter_proc( Time::at( #{date.to_i} ) )%>\n"
255
+ end
256
+ def section_end( date )
257
+ "<%=section_leave_proc( Time::at( #{date.to_i} ) )%>\n"
258
+ end
259
+ def block_title?( fragment )
260
+ case fragment.anchor_type
261
+ when :H3
262
+ true
263
+ else
264
+ false
265
+ end
266
+ end
267
+ def p_start
268
+ "<P>"
269
+ end
270
+ def p_end
271
+ "</P>"
272
+ end
273
+ def pre_start
274
+ "<PRE>"
275
+ end
276
+ def pre_end
277
+ "</PRE>"
278
+ end
279
+ end
280
+
281
+ class EtdiaryDiary
282
+ include BaseDiary
283
+ include CategorizableDiary
284
+
285
+ TAG_BEG_REGEXP = /\A<([A-Za-z][0-9A-Za-z]*)([^>]*)>([^\r]*)\z/
286
+ TAG_END_REGEXP = /\A([^\r]*)<\/([A-Za-z][0-9A-Za-z]*)>\n*\z/
287
+ PRE_REGEXP = /\A<[Pp][Rr][Ee][^>]*>([^\r]*)<\/[Pp][Rr][Ee]>\n*\z/
288
+ TITLE_REGEXP = /\A<<([^\r]*?)>>[^>]/
289
+
290
+ def initialize( date, title, body, modified = Time::now )
291
+ init_diary
292
+ set_date( date )
293
+ set_title( title )
294
+ @sections = []
295
+ if body != '' then
296
+ append( body )
297
+ end
298
+ @last_modified = modified
299
+ end
300
+
301
+ def style
302
+ 'etDiary'
303
+ end
304
+
305
+ def replace( date, title, body )
306
+ set_date( date )
307
+ set_title( title )
308
+ @sections = []
309
+ append( body )
310
+ end
311
+
312
+ def append( body, author = nil )
313
+ section = nil
314
+ buffer = nil
315
+ tag_kind = nil
316
+ body.gsub(/\r/,'').sub(/\A\n*/,'').sub(/\n*\z/,"\n\n").each_line('') do |fragment|
317
+ if buffer and TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
318
+ section << buffer + fragment.sub(/\n*\z/,"\n\n")
319
+ tag_kind = nil
320
+ buffer = nil
321
+ elsif buffer then
322
+ buffer << fragment
323
+ else
324
+ if section
325
+ @sections << section
326
+ end
327
+ title = TITLE_REGEXP.match(fragment+"\n").to_a[1]
328
+ section = EtdiarySection::new( title, author )
329
+ fragment = fragment[ title.length + 4 .. -1 ].sub(/\A\n/,'') if title
330
+ if TAG_BEG_REGEXP =~ fragment then
331
+ tag_kind = $1.downcase
332
+ if TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
333
+ section << fragment.sub(/\n*\z/,"\n\n")
334
+ tag_kind = nil
335
+ else
336
+ buffer = fragment
337
+ end
338
+ else
339
+ section << fragment
340
+ end
341
+ end
342
+ end
343
+ if buffer
344
+ section << buffer << "</#{tag_kind}>(tDiary warning: tag &lt;#{tag_kind}&gt; is not terminated.)"
345
+ end
346
+ if section
347
+ @sections << section
348
+ end
349
+ @last_modified = Time::now
350
+ self
351
+ end
352
+
353
+ def each_paragraph
354
+ @sections.each do |fragment|
355
+ yield fragment
356
+ end
357
+ end
358
+
359
+ def each_section
360
+ section = nil
361
+ each_paragraph do |fragment|
362
+ if section and nil == fragment.anchor_type then
363
+ section << fragment.body
364
+ else
365
+ yield section if section and section.anchor_type
366
+ section = fragment.dup
367
+ section.set_body( [ fragment.body ] )
368
+ end
369
+ end
370
+ yield section if section
371
+ end
372
+
373
+ def add_section(subtitle, body)
374
+ sec = EtdiarySection::new( '' )
375
+ sec.subtitle = subtitle
376
+ sec.body = body
377
+ @sections << sec
378
+ @sections.size
379
+ end
380
+
381
+ def delete_section(index)
382
+ @sections.delete_at(index - 1)
383
+ end
384
+
385
+ def to_src
386
+ src = ''
387
+ each_paragraph do |fragment|
388
+ src << fragment.to_src
389
+ end
390
+ src.sub(/\n*\z/,"\n")
391
+ end
392
+
393
+ def to_html_section(section, factory)
394
+ r = ''
395
+ s = if section.bodies then section.body else nil end
396
+ t = factory.title( date, section )
397
+ if factory.block_title?(section) then
398
+ r << t if t
399
+ t = nil
400
+ end
401
+ if s && PRE_REGEXP =~ s then
402
+ r << factory.p_start << t << factory.p_end << "\n" if t
403
+ r << factory.pre_start
404
+ r << $1.gsub(/&/,"&amp;").gsub(/</,"&lt;").gsub(/>/,"&gt;")
405
+ r << factory.pre_end << "\n"
406
+ elsif s && /\A</ =~ s then
407
+ r << factory.p_start << t << factory.p_end << "\n" if t
408
+ r << s.sub( /\n*\z/, "\n" )
409
+ else
410
+ r << factory.p_start if t || s
411
+ r << t if t
412
+ r << s.sub(/\A\n*/,"\n").sub(/\n*\z/, "\n") if s
413
+ r << factory.p_end << "\n" if t || s
414
+ end
415
+ r
416
+ end
417
+
418
+ def to_html( opt = {'anchor' => true, 'index' => true}, mode = :HTML )
419
+ case mode
420
+ when :CHTML
421
+ f = EtCHtmlFactory::new(opt)
422
+ else
423
+ f = EtHtml4Factory::new(opt)
424
+ end
425
+ r = f.section_start( date )
426
+ each_paragraph do |fragment|
427
+ if :H3 == fragment.anchor_type and r != f.section_start( date ) then
428
+ r << f.section_end( date ) << "\n" << f.section_start( date )
429
+ end
430
+ r << to_html_section(fragment,f)
431
+ end
432
+ r + f.section_end( date )
433
+ end
434
+
435
+ def to_s
436
+ "date=#{date.strftime('%Y%m%d')}, title=#{title}, " \
437
+ + "body=[#{@sections.join('][')}]"
438
+ end
439
+ end
440
+ end
441
+ end
442
+
443
+ # Local Variables:
444
+ # mode: ruby
445
+ # indent-tabs-mode: t
446
+ # tab-width: 3
447
+ # ruby-indent-level: 3
448
+ # End:
@@ -0,0 +1,7 @@
1
+ module Tdiary
2
+ module Style
3
+ module Etdiary
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'tdiary/comment_manager'
3
+ require 'tdiary/referer_manager'
4
+ require 'tdiary/style'
5
+ require 'tdiary/style/etdiary'
@@ -0,0 +1,509 @@
1
+ # -*- coding: utf-8; -*-
2
+ require 'spec_helper'
3
+
4
+ describe TDiary::Style::EtdiaryDiary do
5
+ before do
6
+ @diary = TDiary::Style::EtdiaryDiary.new(Time::at( 1041346800 ), "TITLE", "")
7
+ end
8
+
9
+ describe '#append' do
10
+ before do
11
+ @source = <<-'EOF'
12
+ hogehoge
13
+ fugafuga
14
+
15
+ fugahoge
16
+ hogera
17
+
18
+ <<subTitle>>
19
+ honbun
20
+
21
+ <<<>subTitleH4>>
22
+ honbun
23
+
24
+ <h4>notParagraph</h4>
25
+
26
+ <div>
27
+ Content of block element with blank line.
28
+
29
+ <blockquote>
30
+ hogehoge
31
+ </blockquote>
32
+ </div>
33
+
34
+ <b>Paragraph</b> begin with tag.
35
+
36
+ <pre>
37
+ In <pre>, < and > are automatically escaped.
38
+ </pre>
39
+
40
+ <<>>
41
+ Section without title and anchor.
42
+
43
+ <<<>>>
44
+ Section without title.
45
+ EOF
46
+ @diary.append(@source)
47
+ end
48
+
49
+ context 'HTML' do
50
+ before do
51
+ @html = <<-'EOF'
52
+ <div class="section">
53
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
54
+ <p>
55
+ hogehoge
56
+ fugafuga
57
+ </p>
58
+ <p>
59
+ fugahoge
60
+ hogera
61
+ </p>
62
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
63
+ </div>
64
+
65
+ <div class="section">
66
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
67
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %></h3>
68
+ <p>
69
+ honbun
70
+ </p>
71
+ <h4><%= subtitle_proc( Time::at( 1041346800 ), "subTitleH4" ) %>:</h4>
72
+ <p>
73
+ honbun
74
+ </p>
75
+ <h4>notParagraph</h4>
76
+ <div>
77
+ Content of block element with blank line.
78
+
79
+ <blockquote>
80
+ hogehoge
81
+ </blockquote>
82
+ </div>
83
+ <p>
84
+ <b>Paragraph</b> begin with tag.
85
+ </p>
86
+ <pre>
87
+ In &lt;pre&gt;, &lt; and &gt; are automatically escaped.
88
+ </pre>
89
+ <p><%= subtitle_proc( Time::at( 1041346800 ), nil ) %>
90
+ Section without title and anchor.
91
+ </p>
92
+ <p><a name="p04"></a>
93
+ Section without title.
94
+ </p>
95
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
96
+ </div>
97
+ EOF
98
+ end
99
+ it { @diary.to_html.should eq @html }
100
+ end
101
+
102
+ context 'CHTML' do
103
+ before do
104
+ @html = <<-'EOF'
105
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
106
+ <P>
107
+ hogehoge
108
+ fugafuga
109
+ </P>
110
+ <P>
111
+ fugahoge
112
+ hogera
113
+ </P>
114
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
115
+
116
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
117
+ <H3><%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %></H3>
118
+ <P>
119
+ honbun
120
+ </P>
121
+ <P><%= subtitle_proc( Time::at( 1041346800 ), "subTitleH4" ) %>:
122
+ honbun
123
+ </P>
124
+ <h4>notParagraph</h4>
125
+ <div>
126
+ Content of block element with blank line.
127
+
128
+ <blockquote>
129
+ hogehoge
130
+ </blockquote>
131
+ </div>
132
+ <P>
133
+ <b>Paragraph</b> begin with tag.
134
+ </P>
135
+ <PRE>
136
+ In &lt;pre&gt;, &lt; and &gt; are automatically escaped.
137
+ </PRE>
138
+ <P><%= subtitle_proc( Time::at( 1041346800 ), nil ) %>
139
+ Section without title and anchor.
140
+ </P>
141
+ <P><A NAME="p04"></A>
142
+ Section without title.
143
+ </P>
144
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
145
+ EOF
146
+ end
147
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
148
+ end
149
+
150
+ context 'to_src' do
151
+ it { @diary.to_src.should eq @source }
152
+ end
153
+ end
154
+
155
+ describe '#add_section' do
156
+ before do
157
+ source = <<-'EOF'
158
+ <<subTitle>>
159
+ honbun
160
+
161
+ <<<>subTitleH4>>
162
+ honbun
163
+
164
+ EOF
165
+ @diary.append(source)
166
+ @diary.add_section('subTitle2', 'honbun')
167
+
168
+ @html = <<-'EOF'
169
+ <div class="section">
170
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
171
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "subTitle" ) %></h3>
172
+ <p>
173
+ honbun
174
+ </p>
175
+ <h4><%= subtitle_proc( Time::at( 1041346800 ), "subTitleH4" ) %>:</h4>
176
+ <p>
177
+ honbun
178
+ </p>
179
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
180
+ </div>
181
+
182
+ <div class="section">
183
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
184
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "subTitle2" ) %></h3>
185
+ <p>
186
+ honbun
187
+ </p>
188
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
189
+ </div>
190
+ EOF
191
+ end
192
+ it { @diary.to_html.should eq @html }
193
+ end
194
+
195
+ describe '#delete_section' do
196
+ before do
197
+ source = <<-'EOF'
198
+ <<subTitle>>
199
+ honbun
200
+
201
+ <<subTitle2>>
202
+ honbun
203
+
204
+ EOF
205
+ @diary.append(source)
206
+ @diary.delete_section(1)
207
+
208
+ @html = <<-'EOF'
209
+ <div class="section">
210
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
211
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "subTitle2" ) %></h3>
212
+ <p>
213
+ honbun
214
+ </p>
215
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
216
+ </div>
217
+ EOF
218
+ end
219
+ it { @diary.to_html.should eq @html }
220
+ end
221
+
222
+ describe '#replace' do
223
+ before do
224
+ source = <<-'EOF'
225
+ <<subTitle>>
226
+ honbun
227
+
228
+ <<<>subTitleH4>>
229
+ honbun
230
+
231
+ EOF
232
+ @diary.append(source)
233
+
234
+ replaced = <<-'EOF'
235
+ <<replaceTitle>>
236
+ replace
237
+
238
+ <<<>replaceTitleH4>>
239
+ replace
240
+
241
+ EOF
242
+ @diary.replace(Time::at( 1041346800 ), "TITLE", replaced)
243
+
244
+ @html = <<-'EOF'
245
+ <div class="section">
246
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
247
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "replaceTitle" ) %></h3>
248
+ <p>
249
+ replace
250
+ </p>
251
+ <h4><%= subtitle_proc( Time::at( 1041346800 ), "replaceTitleH4" ) %>:</h4>
252
+ <p>
253
+ replace
254
+ </p>
255
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
256
+ </div>
257
+ EOF
258
+ end
259
+ it { @diary.to_html.should eq @html }
260
+ end
261
+
262
+ describe 'test_etdiary_unterminated_tag' do
263
+ before do
264
+ source = <<-'EOF'
265
+ <p>
266
+ paragraph
267
+ </q>
268
+ EOF
269
+ @diary.append(source)
270
+ end
271
+
272
+ context 'HTML' do
273
+ before do
274
+ @html = <<-'EOF'
275
+ <div class="section">
276
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
277
+ <p>
278
+ paragraph
279
+ </q>
280
+
281
+ </p>(tDiary warning: tag &lt;p&gt; is not terminated.)
282
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
283
+ </div>
284
+ EOF
285
+ end
286
+ it { @diary.to_html.should eq @html }
287
+ end
288
+
289
+ context 'CHTML' do
290
+ before do
291
+ @html = <<-'EOF'
292
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
293
+ <p>
294
+ paragraph
295
+ </q>
296
+
297
+ </p>(tDiary warning: tag &lt;p&gt; is not terminated.)
298
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
299
+ EOF
300
+ end
301
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
302
+ end
303
+ end
304
+
305
+ describe 'test_etdiary_null' do
306
+ before do
307
+ source = <<-'EOF'
308
+ EOF
309
+ @diary.append(source)
310
+ end
311
+
312
+ context 'HTML' do
313
+ before do
314
+ @html = <<-'EOF'
315
+ <div class="section">
316
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
317
+ <p>
318
+ </p>
319
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
320
+ </div>
321
+ EOF
322
+ end
323
+ it { @diary.to_html.should eq @html }
324
+ end
325
+
326
+ context 'CHTML' do
327
+ before do
328
+ @html = <<-'EOF'
329
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
330
+ <P>
331
+ </P>
332
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
333
+ EOF
334
+ end
335
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
336
+ end
337
+ end
338
+
339
+ describe 'test_etdiary_sectionAtBeginning' do
340
+ before do
341
+ source = <<-'EOF'
342
+ <<hoge>>
343
+ fuga
344
+ EOF
345
+ @diary.append(source)
346
+ end
347
+
348
+ context 'HTML' do
349
+ before do
350
+ @html = <<-'EOF'
351
+ <div class="section">
352
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
353
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %></h3>
354
+ <p>
355
+ fuga
356
+ </p>
357
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
358
+ </div>
359
+ EOF
360
+ end
361
+ it { @diary.to_html.should eq @html }
362
+ end
363
+
364
+ context 'CHTML' do
365
+ before do
366
+ @html = <<-'EOF'
367
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
368
+ <H3><%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %></H3>
369
+ <P>
370
+ fuga
371
+ </P>
372
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
373
+ EOF
374
+ end
375
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
376
+ end
377
+ end
378
+
379
+ describe 'test_etdiary_appending' do
380
+ before do
381
+ source = <<-'EOF'
382
+ <p>para1</p>
383
+ EOF
384
+
385
+ sourceAppended = <<-'EOF'
386
+ <p>para2</p>
387
+ EOF
388
+ @diary.append(source)
389
+ @diary.append(sourceAppended)
390
+ end
391
+
392
+ context 'HTML' do
393
+ before do
394
+ @html = <<-'EOF'
395
+ <div class="section">
396
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
397
+ <p>para1</p>
398
+ <p>para2</p>
399
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
400
+ </div>
401
+ EOF
402
+ end
403
+ it { @diary.to_html.should eq @html }
404
+ end
405
+
406
+ context 'CHTML' do
407
+ before do
408
+ @html = <<-'EOF'
409
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
410
+ <p>para1</p>
411
+ <p>para2</p>
412
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
413
+ EOF
414
+ end
415
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
416
+ end
417
+ end
418
+
419
+ # 2004.08.12 Reported by Shun-ichi TAHARA, thanks!
420
+ describe 'test_etdiary_subsequentPREtoSectionTitle' do
421
+ before do
422
+ source = <<-'EOF'
423
+ <<hoge>>
424
+ <pre>
425
+ hoge
426
+
427
+ fuga
428
+ </pre>
429
+ EOF
430
+ @diary.append(source)
431
+ end
432
+
433
+ context 'HTML' do
434
+ before do
435
+ @html = <<-'EOF'
436
+ <div class="section">
437
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
438
+ <h3><%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %></h3>
439
+ <pre>
440
+ hoge
441
+
442
+ fuga
443
+ </pre>
444
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
445
+ </div>
446
+ EOF
447
+ end
448
+ it { @diary.to_html.should eq @html }
449
+ end
450
+
451
+ context 'CHTML' do
452
+ before do
453
+ @html = <<-'EOF'
454
+ <%=section_enter_proc( Time::at( 1041346800 ) )%>
455
+ <H3><%= subtitle_proc( Time::at( 1041346800 ), "hoge" ) %></H3>
456
+ <PRE>
457
+ hoge
458
+
459
+ fuga
460
+ </PRE>
461
+ <%=section_leave_proc( Time::at( 1041346800 ) )%>
462
+ EOF
463
+ end
464
+ it { @diary.to_html({'anchor' => true, 'index' => true}, :CHTML).should eq @html }
465
+ end
466
+ end
467
+
468
+ # 2004.08.19 Reported by Shun-ichi TAHARA, thanks!
469
+ describe 'test_etdiary_badAnchorNumber' do
470
+ before do
471
+ source = <<-'EOF'
472
+ sect0-para0
473
+
474
+ <<sect1>>
475
+ sect1-para0
476
+
477
+ sect1-para1
478
+
479
+ sect1-para2
480
+
481
+ <<sect2>>
482
+ sect2-para0
483
+ EOF
484
+
485
+ @diary.append(source)
486
+ sections = []
487
+ @diary.each_section { |sect|
488
+ sections << sect
489
+ }
490
+
491
+ @anchorNumber = 0
492
+ @section = sections.find do |sect|
493
+ @anchorNumber += 1
494
+ (sect.subtitle == "sect2")
495
+ end
496
+ end
497
+ it { @section.should_not be_nil }
498
+ it { @anchorNumber.should eq 2 }
499
+ # github issue #271
500
+ it { @section.body_to_html.should eq "<p>sect2-para0\n</p>\n" }
501
+ end
502
+ end
503
+
504
+ # Local Variables:
505
+ # mode: ruby
506
+ # indent-tabs-mode: t
507
+ # tab-width: 3
508
+ # ruby-indent-level: 3
509
+ # End:
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tdiary/style/etdiary/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tdiary-style-etdiary"
8
+ spec.version = Tdiary::Style::Etdiary::VERSION
9
+ spec.authors = ["SHIBATA Hiroshi"]
10
+ spec.email = ["shibata.hiroshi@gmail.com"]
11
+ spec.description = %q{etDiary Style for tDiary}
12
+ spec.summary = %q{etDiary Style for tDiary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdiary-style-etdiary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SHIBATA Hiroshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: etDiary Style for tDiary
56
+ email:
57
+ - shibata.hiroshi@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/tdiary/style/etdiary.rb
70
+ - lib/tdiary/style/etdiary/version.rb
71
+ - spec/spec_helper.rb
72
+ - spec/tdiary/style/etdiary_spec.rb
73
+ - tdiary-style-etdiary.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.1.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: etDiary Style for tDiary
98
+ test_files:
99
+ - spec/spec_helper.rb
100
+ - spec/tdiary/style/etdiary_spec.rb
101
+ has_rdoc: