Show markdown description text on item detail page
* Update build process to *not* copy over prerendered pages during a regular build (only during a `dist` build) * Add dependency on npm "markdown" package and include it in the scripts loaded in the default layout * Update the Item model to be able to load from a *.cg file * Add an ItemParser to process the `item.cg` file * Update the general parser to be able to work with HereDoc-style text blocks * Add a markdown-specific stylesheet * Add a sample of the `item.cg` file format (Advanced Crafting Table)
This commit is contained in:
@@ -78,7 +78,7 @@ module.exports = class CommandParserVersionBase
|
||||
line = line.trim()
|
||||
return [] if line.length is 0
|
||||
|
||||
hereDoc = @_parseHereDoc line
|
||||
[line, hereDoc] = @_parseHereDoc line
|
||||
|
||||
lineParts = (part.trim() for part in line.split(';'))
|
||||
commands = []
|
||||
@@ -89,8 +89,10 @@ module.exports = class CommandParserVersionBase
|
||||
if not match? then throw new Error "Expected <command>: <args>, but found: \"#{linePart}\""
|
||||
|
||||
args = []
|
||||
args = (s.trim() for s in match[2].split(',')) if match[2]?
|
||||
args.push hereDoc if hereDoc
|
||||
args = (s for s in match[2].split(',') when s.length > 0) if match[2]?
|
||||
args = (s.trim() for s in args)
|
||||
args = (s for s in args when s.length > 0)
|
||||
args.push hereDoc if hereDoc?
|
||||
commands.push name:match[1], args:args
|
||||
|
||||
return commands
|
||||
@@ -107,9 +109,11 @@ module.exports = class CommandParserVersionBase
|
||||
|
||||
_parseHereDoc: (line)->
|
||||
hereDocIndex = line.indexOf '<<-'
|
||||
return null unless hereDocIndex isnt -1
|
||||
return [line, null] unless hereDocIndex isnt -1
|
||||
|
||||
hereDocStopText = line[hereDocIndex+3...line.length]
|
||||
line = line[0...hereDocIndex]
|
||||
|
||||
hereDocLines = []
|
||||
while true
|
||||
@_lineNumber += 1
|
||||
@@ -120,11 +124,11 @@ module.exports = class CommandParserVersionBase
|
||||
hereDocLines.push nextLine
|
||||
|
||||
shortestIndent = Number.MAX_VALUE
|
||||
for line in hereDocLines
|
||||
shortestIndent = Math.min line.match(/( *).*/)[1].length, shortestIndent
|
||||
for hereDocLine in hereDocLines
|
||||
shortestIndent = Math.min hereDocLine.match(/( *).*/)[1].length, shortestIndent
|
||||
|
||||
for i in [0...hereDocLines.length]
|
||||
hereDocLines[i] = hereDocLines[i][shortestIndent..]
|
||||
|
||||
return null unless hereDocLines.length > 0
|
||||
return hereDocLines.join '\n'
|
||||
return [line, null] unless hereDocLines.length > 0
|
||||
return [line, hereDocLines.join('\n')]
|
||||
|
||||
@@ -22,16 +22,17 @@ module.exports = class ItemParserV1 extends CommandParserVersionBase
|
||||
# Command Methods ##############################################################################
|
||||
|
||||
_command_description: (textParts...)->
|
||||
@_rawData.text ?= ''
|
||||
@_rawData.text += textParts.join ', '
|
||||
@_rawData.description ?= ''
|
||||
@_rawData.description += textParts.join ', '
|
||||
|
||||
_command_officialUrl: (officialUrl)->
|
||||
if @_rawData.officialUrl? then throw new Error 'duplicate declaration of "officialUrl"'
|
||||
if officialUrl.length is 0 then throw new Error 'officialUrl cannot be empty'
|
||||
@_rawData.officialUrl = officialUrl
|
||||
|
||||
_command_video: (youTubeId, name)->
|
||||
_command_video: (youTubeId, nameParts...)->
|
||||
if not youTubeId?.length then throw new Error 'video declaration requires a YouTubeID'
|
||||
name = nameParts.join ', '
|
||||
if not name?.length then throw new Error 'video declaration requires a name'
|
||||
|
||||
@_rawData.videos ?= []
|
||||
@@ -40,6 +41,6 @@ module.exports = class ItemParserV1 extends CommandParserVersionBase
|
||||
# Object Building Methods ######################################################################
|
||||
|
||||
_buildItem: (rawData, model)->
|
||||
item.description = rawData.description if rawData.description
|
||||
item.officialUrl = rawData.officialUrl if rawData.officialUrl
|
||||
item.videos = rawData.videos if rawData.videos
|
||||
model.description = rawData.description if rawData.description
|
||||
model.officialUrl = rawData.officialUrl if rawData.officialUrl
|
||||
model.videos = rawData.videos if rawData.videos
|
||||
|
||||
Reference in New Issue
Block a user