lib/helpline/update.rb in helpline-0.2.1 vs lib/helpline/update.rb in helpline-0.2.2
- old
+ new
@@ -13,20 +13,23 @@
dumpdata['defs'] = []
dumpdata['pages'] = []
sources.each { |source|
pagedata = {}
+ projectname = ''
if File.exist?(source)
puts "-----------------ページデータをJSONデータ(#{source})から取得"
data = JSON.parse(File.read(source))
+ projectname = data['name']
data['pages'].each { |page|
title = page['title']
puts "...#{title}"
pagedata[title] = page['lines']
}
elsif source =~ /^[a-zA-Z\-]+$/ # たぶんHelpLineプロジェクト
puts "-----------------ページデータをScrapbox(#{source})から取得"
+ projectname = source
project = Scrapbox::Project.new(source)
project.pages.each { |title,page|
puts "...#{title}"
pagedata[title] = page.text.split(/\n/)
}
@@ -69,39 +72,39 @@
src = nil
code = []
end
}
puts "-----------------HelpLineデータを検出"
- pagedata.each { |title,pagedata|
+ pagedata.each { |title,data|
# puts "...#{title}"
dumpdata['pages'] << title
processing_defs = false
- codeindent = nil
- pagedata.each { |line|
- if !codeindent
- if line =~ /^code:/
- codeindent = 0
- next
- end
- else
- line =~ /^(\s*)/
- if $1.length < codeindent + 1
- codeindent = nil
- else
- next
- end
- end
- if line =~ /^[\$\%\?]/
- if line =~ /^\%/ && !processing_defs
- puts "'$'で始まる用例定義なしでコマンドを定義しようとしています"
+ cmd_defined = false
+ data.each { |line|
+ if line =~ /^[\$\?]/
+ dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
+ cmd_defined = false
+ processing_defs = true
+ elsif line =~ /^\%/
+ if !processing_defs
+ puts "'$'で始まる用例定義なしでコマンドを定義しようとしています (#{title})"
exit
end
dumpdata['defs'] << "#{line} {#{dumpdata['pages'].length-1}}"
- processing_defs = true
+ cmd_defined = true
+ processing_defs = false
+ elsif processing_defs && !cmd_defined
+ dumpdata['defs'] << "% open 'https://Scrapbox.io/#{projectname}/#{title}' {#{dumpdata['pages'].length-1}}"
+ cmd_defined = false
+ processing_defs = false
else
+ cmd_defined = false
processing_defs = false
end
}
+ if processing_defs && !cmd_defined
+ dumpdata['defs'] << "% open 'https://Scrapbox.io/#{projectname}/#{title}' {#{dumpdata['pages'].length-1}}"
+ end
}
}
File.open(datafile,"w"){ |f|
f.puts dumpdata.to_json