Skip to content

Commit

Permalink
split nav metadata into head and body components
Browse files Browse the repository at this point in the history
  • Loading branch information
TomWoodward committed Feb 18, 2014
1 parent f1187d9 commit 30a292b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
36 changes: 23 additions & 13 deletions scripts/gh-book/opf-file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ define [
'cs!gh-book/uuid'
'hbs!templates/gh-book/defaults/opf'
'hbs!templates/gh-book/defaults/nav'
'hbs!templates/gh-book/nav-metadata'
'hbs!templates/gh-book/nav-body-metadata'
'hbs!templates/gh-book/nav-head-metadata'
], (
Backbone,
mediaTypes,
Expand All @@ -23,7 +24,8 @@ define [
uuid,
defaultOpf,
defaultNav,
navMetadata
navBodyMetadata,
navHeadMetadata
) ->

SAVE_DELAY = 10 # ms
Expand Down Expand Up @@ -69,9 +71,12 @@ define [
# This way we can ignore firing events when Backbone is parsing as well as
# when we are internally updating models.
setNavModel = (options) =>
console.log 'here'
if not options.doNotReparse
console.log 'here2'
options.doNotReparse = true
@navModel.set 'body', @_serializeNavModel(), options
@navModel.set 'head', @_serializeNavModelHead(), options
@navModel.set 'body', @_serializeNavModelBody(), options

# if we're updating the nav the spine also probably needs to be updated
@_buildSpine()
Expand Down Expand Up @@ -99,7 +104,9 @@ define [
return if not value

container = @$xml.find('metadata')
selector = tagName.replace(':', '\\:')

# remove any namespace on the tagname so jquery will work
selector = tagName.replace(/.*:/, '')

element = @$xml[0].createElement(tagName)

Expand Down Expand Up @@ -147,7 +154,10 @@ define [
return if not values.length

container = @$xml.find('metadata')
selector = tagName.replace(':', '\\:')

# remove any namespace on the tagname so jquery will work
selector = tagName.replace(/.*:/, '')

template = @$xml[0].createElement(tagName)

_.forIn attributes, (value, key) ->
Expand Down Expand Up @@ -184,7 +194,7 @@ define [

container = @$xml.find('metadata')
template = "<dc:subject></dc:subject>"
@$xml.find('dc\\:subject').not('[xsi\\:type="http://github.com/Connexions/rhaptos.cnxmlutils/rhaptos/cnxmlutils/schema"]').remove()
@$xml.find('subject').not('[xsi\\:type="http://github.com/Connexions/rhaptos.cnxmlutils/rhaptos/cnxmlutils/schema"]').remove()

_.each(value, (keyword) ->
container.append(' ')
Expand All @@ -202,7 +212,7 @@ define [
return if not creators.length

# remove the existing ones so we don't get dupes
@$xml.find('dc\\:creator[id^="'+type+'"]').remove()
@$xml.find('creator[id^="'+type+'"]').remove()
@$xml.find('meta[refines^="#'+type+'"]').remove()

container = @$xml.find('metadata')
Expand Down Expand Up @@ -452,12 +462,12 @@ define [

@_markDirty({}) if start != @serialize()

_serializeNavModel: () ->
$wrapper = $('<div></div>')
_serializeNavModelHead: () ->
return navHeadMetadata(@toJSON())

$wrapper
.append(navMetadata(@toJSON()))
.append('<nav></nav>')
_serializeNavModelBody: () ->
$wrapper = $('<div></div>')
$wrapper.append('<nav></nav>')

$nav = $wrapper.find 'nav'

Expand Down Expand Up @@ -494,7 +504,7 @@ define [
# Trim the HTML and put newlines between elements
html = $wrapper.html()
html = html.replace(/></g, '>\n<')
return html
return navBodyMetadata(@toJSON()) + html


parse: (json) ->
Expand Down
5 changes: 5 additions & 0 deletions templates/gh-book/nav-body-metadata.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1 itemprop="name">{{ title }}</h1>
{{#if authors }}<span class="authors">By: {{#each authors }}{{#if @index }}, {{/if}}<span itemprop="author">{{ this }}</span>{{/each}}</span>{{/if}}
{{#if publishers }}<span class="publisher">Published By: {{#each publishers }}{{#if @index }}, {{/if}}<span itemprop="publisher">{{ this }}</span>{{/each}}</span>{{/if}}
{{#if description }}<p itemprop="description">{{ description }}</p>{{/if}}
<h1>Table of Contents</h1>
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<title>{{ title }}</title>
{{#if language }}<meta itemprop="inLanguage" content="{{ language }}" />{{/if}}
{{#if rights }}<meta property="dc:license" content="{{ rights }}" />{{/if}}
{{#if rightsUrl }}<meta property="lrmi:useRightsUrl" content="{{ rightsUrl }}" />{{/if}}
{{#if dateModified }}<meta itemprop="dateModified" content="{{ dateModified }}" />{{/if}}
{{#if datePublished }}<meta itemprop="dateCreated" content="{{ datePublished }}" />{{/if}}
{{#each subject}}<meta itemprop="about" content="{{ this }}" />
{{#if language }}<meta itemprop="inLanguage" content="{{ language }}"></meta>{{/if}}
{{#if rights }}<meta property="dc:license" content="{{ rights }}"></meta>{{/if}}
{{#if rightsUrl }}<meta property="lrmi:useRightsUrl" content="{{ rightsUrl }}"></meta>{{/if}}
{{#if dateModified }}<meta itemprop="dateModified" content="{{ dateModified }}"></meta>{{/if}}
{{#if datePublished }}<meta itemprop="dateCreated" content="{{ datePublished }}"></meta>{{/if}}
{{#each subject}}<meta itemprop="about" content="{{ this }}"></meta>
{{/each}}
{{#each keywords}}<meta itemprop="keywords" content="{{ this }}" />
{{#each keywords}}<meta itemprop="keywords" content="{{ this }}"></meta>
{{/each}}
{{#each rightsHolders}}<meta itemprop="copyrightHolder" content="{{ this }}" />
{{#each rightsHolders}}<meta itemprop="copyrightHolder" content="{{ this }}"></meta>
{{/each}}
{{#each editors }}<meta itemprop="editor" content="{{ this }}" />
{{#each editors }}<meta itemprop="editor" content="{{ this }}"></meta>
{{/each}}
{{#each translators }}<meta id="translator{{@key }}" itemprop="contributor" content="{{ this }}"/>
<meta refines="#translator{{@key }}" property="role" scheme="marc:relators" content="trl" />
{{#each translators }}<meta id="translator{{@key }}" itemprop="contributor" content="{{ this }}"></meta>
<meta refines="#translator{{@key }}" property="role" scheme="marc:relators" content="trl"></meta>
{{/each}}
{{#each illustrators }}<meta itemprop="illustrator" content="{{ this }}" />
{{#each illustrators }}<meta itemprop="illustrator" content="{{ this }}"></meta>
{{/each}}

<h1 itemprop="name">{{ title }}</h1>
{{#if authors }}<span class="authors">By: {{#each authors }}{{#if @index }}, {{/if}}<span itemprop="author">{{ this }}</span>{{/each}}</span>{{/if}}
{{#if publishers }}<span class="publisher">Published By: {{#each publishers }}{{#if @index }}, {{/if}}<span itemprop="publisher">{{ this }}</span>{{/each}}</span>{{/if}}
{{#if description }}<p itemprop="description">{{ description }}</p>{{/if}}
<h1>Table of Contents</h1>

0 comments on commit 30a292b

Please sign in to comment.