# -*- coding: utf-8; -*- require 'spec_helper' describe TDiary::Style::GfmDiary do before do @diary = TDiary::Style::GfmDiary.new(Time.at( 1041346800 ), "TITLE", "") end describe '#append' do before do @source = <<-'EOF' # subTitle honbun ## subTitleH4 honbun ``` # comment in code block ``` EOF @diary.append(@source) end context 'HTML' do before do @html = <<-'EOF'
honbun
honbun
# comment in code block
<%=section_leave_proc( Time.at( 1041346800 ) )%>
honbun
honbun
# comment in code block
<%=section_leave_proc( Time.at( 1041346800 ) )%>
EOF
end
it { @diary.to_html({}, :CHTML).should eq @html }
end
context 'to_src' do
it { @diary.to_src.should eq @source }
end
end
describe '#replace' do
before do
source = <<-'EOF'
# subTitle
honbun
## subTitleH4
honbun
EOF
@diary.append(source)
replaced = <<-'EOF'
# replaceTitle
replace
## replaceTitleH4
replace
EOF
@diary.replace(Time.at( 1041346800 ), "TITLE", replaced)
@html = <<-'EOF'
replace
replace
<%=section_leave_proc( Time.at( 1041346800 ) )%>@foo
http://example.com is example.com
<%=section_leave_proc( Time.at( 1041346800 ) )%>example is example.com
<%=section_leave_proc( Time.at( 1041346800 ) )%><%=plugin 'val'%>
<%=plugin "val", 'val'%>
<%=section_leave_proc( Time.at( 1041346800 ) )%><%=plugin 'http://www.example.com/foo.html', "https://www.example.com/bar.html"%>
<%=section_leave_proc( Time.at( 1041346800 ) )%><%=my "20120101p01", "20120101p01" %>
<%=my "20120101p01", "Link" %>
<%=section_leave_proc( Time.at( 1041346800 ) )%> def class
@foo = 'bar'
end
@a_matsuda is amatsuda
<%=isbn_left_image ''%>
<%=section_leave_proc( Time.at( 1041346800 ) )%>@a_matsuda is amatsuda
<%=section_leave_proc( Time.at( 1041346800 ) )%>' do before do source = <<-'EOF' # subTitle p :some_code @a_matsuda is amatsuda EOF @diary.append(source) @html = <<-'EOF'<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end describe 'with<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
p :some_code
@a_matsuda is amatsuda
<%=section_leave_proc( Time.at( 1041346800 ) )%>' do before do source = <<-'EOF' # subTitle `:some_code` @a_matsuda is amatsuda EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end end context 'emoji' do describe 'in plain context' do before do source = <<-'EOF' # subTitle :sushi: は美味しい EOF @diary.append(source) @html = <<-'EOF'<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
:some_code
@a_matsuda is amatsuda
<%=section_leave_proc( Time.at( 1041346800 ) )%><%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end describe 'in (multiline)<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
は美味しい
<%=section_leave_proc( Time.at( 1041346800 ) )%>' do before do source = <<-'EOF' # subTitle ``` :sushi: は 美味しい ``` EOF @diary.append(source) @html = <<-'EOF'<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end describe 'in<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
<%=section_leave_proc( Time.at( 1041346800 ) )%>:sushi: は 美味しい
' do before do source = <<-'EOF' # subTitle `:sushi:` は美味しい EOF @diary.append(source) @html = <<-'EOF'
<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end describe 'in<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
<%=section_leave_proc( Time.at( 1041346800 ) )%>
:sushi:
は美味しい(with attribute)' do before do source = <<-'EOF' # subTitle
:sushi:
は美味しい EOF @diary.append(source) @html = <<-'EOF'<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end end describe 'do not modify original string' do before do @orig_source = <<-'EOF' # subTitle {{fn 'テスト'}}" EOF @source = @orig_source.dup @diary.append(@source) @diary.to_html @section = nil @diary.each_section{|x| @section = x} end it { expect(@section.body).to eq("\n"+@orig_source.lines.to_a.last+"\n") } end describe 'stashes in pre, code, plugin' do before do source = <<-'EOF' # subTitle ``` ruby -e "puts \"hello, world.\"" ``` `ruby -e "puts \"hello, world.\""` {{plugin "\0", "\1", "\2"}} EOF @diary.append(source) @html = <<-'EOF'<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
<%=section_leave_proc( Time.at( 1041346800 ) )%>
:sushi:
は美味しい<%=section_enter_proc( Time.at( 1041346800 ) )%>EOF end it { @diary.to_html.should eq @html } end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End:<%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %>
ruby -e "puts \"hello, world.\""
ruby -e "puts \"hello, world.\""
<%=plugin "\0", "\1", "\2"%>
<%=section_leave_proc( Time.at( 1041346800 ) )%>