# encoding: utf-8
=begin
* Name: SiSU
** Description: documents, structuring, processing, publishing, search
*** Description: json output logic, flow
** Author: Ralph Amissah
[ralph@amissah.com]
[ralph.amissah@gmail.com]
** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
All Rights Reserved.
** License: GPL 3 or later:
SiSU, a framework for document structuring, publishing and search
Copyright (C) Ralph Amissah
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see [http://www.gnu.org/licenses/].
If you have Internet connection, the latest version of the GPL should be
available at these locations:
[http://www.fsf.org/licensing/licenses/gpl.html]
[http://www.gnu.org/licenses/gpl.html]
** SiSU uses:
* Standard SiSU markup syntax,
* Standard SiSU meta-markup syntax, and the
* Standard SiSU object citation numbering and system
** Hompages:
[http://www.jus.uio.no/sisu]
[http://www.sisudoc.org]
** Git
[http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
[http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/json_format.rb;hb=HEAD]
=end
module SiSU_JSON_Format
require_relative 'dp' # dp.rb
require_relative 'json_parts' # json_parts.rb
include SiSU_Param
class ParagraphNumber
def initialize(md,paranum)
@md=md
@paranum=(paranum \
? (/(\d+)/m.match(paranum)[1])
: nil)
end
def display
p_num_display=if @paranum
@paranum.gsub(/(\d+)/,
'' +
' \1')
else ''
end
p_num_display
end
def name
p_num_name=@paranum.gsub(/(\d+)/,'')
p_num_name
end
def goto
p_num_goto=@paranum.gsub(/(\d+)/,'')
p_num_goto
end
end
class HeadInformation
include SiSU_Parts_JSON
def initialize #dc rdf
@full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords=''
@md=@@md
# DublinCore 1 - title
@rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n}
if defined? @md.title.full \
and @md.title.full # DublinCore 1 - title
@rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n}
@full_title=%{\n}
end
if defined? @md.creator.author \
and @md.creator.author # DublinCore 2 - creator/author (author)
@rdf_author=%{ dc.author="#{@md.creator.author}"\n}
@author=%{\n}
end
if defined? @md.classify.subject \
and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???)
@rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n}
@subject=%{\n}
end
if defined? @md.notes.description \
and @md.notes.description=~/\S+/ # DublinCore 4 - description
@rdf_description=%{ dc.description="#{@md.notes.description}"\n}
@description=%{\n}
end
if defined? @md.publisher \
and @md.publisher=~/\S+/ # DublinCore 5 - publisher (current copy published by)
@rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n}
@publisher=%{\n}
end
if defined? @md.creator.contributor \
and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor
@rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n}
@contributor=%{\n}
end
if defined? @md.date.published \
and @md.date.published # DublinCore 7 - date year-mm-dd
@rdf_date=%{ dc.date="#{@md.date.published}"\n}
@date=%{\n}
end
if defined? @md.date.created \
and @md.date.created # DublinCore 7 - date.created year-mm-dd
@rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n}
@date_created=%{\n}
end
if defined? @md.date.issued \
and @md.date.issued # DublinCore 7 - date.issued year-mm-dd
@rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n}
@date_issued=%{\n}
end
if defined? @md.date.available \
and @md.date.available # DublinCore 7 - date.available year-mm-dd
@rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n}
@date_available=%{\n}
end
if defined? @md.date.valid \
and @md.date.valid # DublinCore 7 - date.valid year-mm-dd
@rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n}
@date_valid=%{\n}
end
if defined? @md.date.modified \
and @md.date.modified # DublinCore 7 - date.modified year-mm-dd
@rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n}
@date_modified=%{\n}
end
if defined? @md.notes.coverage \
and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage
@rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n}
@coverage=%{\n}
end
if defined? @md.notes.relation \
and @md.notes.relation=~/\S+/ # DublinCore 13 - relation
@rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n}
@relation=%{\n}
end
if defined? @md.notes.type \
and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc)
@rdf_type=%{ dc.type="#{@md.notes.type}"\n}
@type=%{\n}
end
if defined? @md.notes.format \
and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type)
@rdf_format=%{ dc.format="#{@md.notes.format}"\n}
@format=%{\n}
end
#if defined? @md.identifier.sisupod \
#and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free)
# @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n}
# @identifier=%{\n}
#end
if defined? @md.original.source \
and @md.original.source=~/\S+/ # DublinCore 11 - source (document source)
@rdf_source=%{ dc.source="#{@md.original.source}"\n}
@source=%{\n}
end
if defined? @md.original.language \
and @md.original.language=~/\S+/ # DublinCore 12 - language (English)
@rdf_language=%{ dc.language="#{@md.original.title}"\n}
@language=%{\n}
end
if defined? @md.rights.all \
and @md.rights.all=~/\S+/ # DublinCore 15 - rights
rights=meta_content_clean(@md.rights.all)
copyright=meta_content_clean(@md.rights.copyright.all)
@rdf_rights=%{ dc.rights="#{rights}"\n}
@rights=%{\n}
end
@copyright=%{\n} \
if @md.rights.copyright.all # possibly redundant see dc.rights
@owner=%{\n} if @md.owner
@keywords=%{\n} if @md.keywords
@index='index'
end
def meta_content_clean(content='')
content=if not content.nil?
content=content.tr('"',"'").
gsub(/&/,'&')
content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content)
else content
end
end
def table_close
' '
end
def toc_head
<#{@txt} #{@trailer}
"
end
def table_css_end #
'
#{@txt}
#{the_margin.num_css} #{the_table_close}} end def bold_header @txt=@txt.gsub(/[1-9]~(\S+)/,''). gsub(/[1-9]~/,'') %{#{@txt}
#{the_margin.num_css} #{the_table_close}} end def toc_head_copy_at %{#{@txt}
\n} end def center %{#{@txt}
\n} end def bold %{#{@txt}
\n} end def center_bold %{#{@txt}
\n} end end end __END__