From fc6b1b35cd190615f73c0acab8c2636167e13754 Mon Sep 17 00:00:00 2001 From: Christian Genco Date: Mon, 6 Apr 2015 14:03:20 -0500 Subject: [PATCH] indentation works; not exactly sure how --- generate.coffee | 209 ++++++++++++++++++------------------------------ guide.pdf | Bin 3743 -> 4514 bytes test.coffee.md | 7 +- 3 files changed, 84 insertions(+), 132 deletions(-) diff --git a/generate.coffee b/generate.coffee index 075ace3..27a692d 100644 --- a/generate.coffee +++ b/generate.coffee @@ -19,67 +19,26 @@ vm.runInNewContext coffeeMode, CodeMirror: CodeMirror # style definitions for markdown styles = - # h1: - # font: 'Times-Roman' - # fontSize: 25 - # padding: 15 - # h2: - # font: 'Times-Roman' - # fontSize: 18 - # padding: 10 - # h3: - # font: 'Times-Roman' - # fontSize: 18 - # padding: 10 - meta: + default: font: 'Times-Roman' fontSize: 12 lineGap: 24 align: 'left' + meta: indent: 0 title: - font: 'Times-Roman' - fontSize: 12 - lineGap: 24 align: 'center' para: - font: 'Times-Roman' - fontSize: 12 - lineGap: 24 - align: 'left' - indent: 72 - # padding: 10 - # code: - # font: 'Times-Roman' - # fontSize: 9 - # code_block: - # padding: 10 - # background: '#2c2c2c' - # inlinecode: - # font: 'Times-Roman' - # fontSize: 10 - # listitem: - # font: 'Times-Roman' - # fontSize: 10 - # padding: 6 - # link: - # font: 'Times-Roman' - # fontSize: 10 - # color: 'blue' - # underline: true - # example: - # font: 'Times-Roman' - # fontSize: 9 - # color: 'black' - # padding: 10 + indent: 72/2 + blockquote: + indent: 0 + color: 'red' + font: 'Times-Italic' + marginLeft: 72 em: font: 'Times-Italic' - align: 'left' strong: font: 'Times-Bold' - align: 'left' - # u: - # underline: true # syntax highlighting colors # based on Github's theme @@ -120,6 +79,7 @@ class Node @text = tree return + # console.dir tree @type = tree.shift() @attrs = {} @@ -130,24 +90,26 @@ class Node @content = while tree.length new Node tree.shift() + # console.log "type =", @type + switch @type when 'header' @type = 'h' + @attrs.level - when 'code_block' - # use code mirror to syntax highlight the code block - code = @content[0].text - @content = [] - CodeMirror.runMode code, 'coffeescript', (text, style) => - color = colors[style] or colors.default - opts = - color: color - continued: text isnt '\n' + # when 'code_block' + # # use code mirror to syntax highlight the code block + # code = @content[0].text + # @content = [] + # CodeMirror.runMode code, 'coffeescript', (text, style) => + # color = colors[style] or colors.default + # opts = + # color: color + # continued: text isnt '\n' - @content.push new Node ['code', opts, text] + # @content.push new Node ['code', opts, text] - @content[@content.length - 1]?.attrs.continued = false - codeBlocks.push code + # @content[@content.length - 1]?.attrs.continued = false + # codeBlocks.push code when 'img' # images are used to generate inline example output @@ -158,7 +120,9 @@ class Node @code = coffee.compile code if code @height = +@attrs.title or 0 - @style = styles[@type] or styles.para + @style = _.extend({}, styles.default, styles[@type]) + # @style.continued = @attrs.continued if @attrs.continued? + # console.log @style # sets the styles on the document for this node setStyle: (doc) -> @@ -168,45 +132,25 @@ class Node if @style.fontSize doc.fontSize @style.fontSize - if @style.color or @attrs.color - doc.fillColor @style.color or @attrs.color + if @style.color + doc.fillColor @style.color else doc.fillColor 'black' - options = {} - options.lineGap = @style.lineGap || 24 - options.align = @style.align - options.indent = @style.indent - # options.paragraphGap = 24 - options.link = @attrs.href or false # override continued link - options.continued = @attrs.continued if @attrs.continued? - return options + # options = _.extend({}, @style) + # # options.lineGap = @style.lineGap + # # options.align = @style.align + # # options.indent = @style.indent + # # options.link = @attrs.href or false # override continued link + # options.continued = @attrs.continued if @attrs.continued? + # console.log "options =", options + # return options + null # renders this node and its subnodes to the document render: (doc, continued = false) -> + console.log "rendering node: ", @ switch @type - when 'example' - @setStyle doc - - # translate all points in the example code to - # the current point in the document - doc.moveDown() - doc.save() - doc.translate(doc.x, doc.y) - x = doc.x - y = doc.y - doc.x = doc.y = 0 - - # run the example code with the document - vm.runInNewContext @code, - doc: doc - lorem: lorem - - # restore points and styles - y += doc.y - doc.restore() - doc.x = x - doc.y = y + @height when 'hr' doc.addPage() else @@ -214,25 +158,31 @@ class Node for fragment, index in @content if fragment.type is 'text' # add a new page for each heading, unless it follows another heading - if @type in ['h1', 'h2'] and lastType? and lastType isnt 'h1' - doc.addPage() + # if @type in ['h1', 'h2'] and lastType? and lastType isnt 'h1' + # doc.addPage() # set styles and whether this fragment is continued (for rich text wrapping) - options = @setStyle doc - options.continued ?= continued or index < @content.length - 1 + @setStyle doc + # @style.continued ?= continued or index < @content.length - 1 + # @style.continued = continued # remove newlines unless this is code - unless @type is 'code' - fragment.text = fragment.text.replace(/[\r\n]\s*/g, ' ') + # unless @type is 'code' + # fragment.text = fragment.text.replace(/[\r\n]\s*/g, ' ') - doc.text fragment.text, options + # console.log "rendering text. continued =", continued, 'attrs.continued =', @attrs.continued + doc.text fragment.text, _.extend({}, @style, {continued: continued or index < @content.length - 1}) else + console.log "rendering fragment #{fragment.type}" fragment.render doc, index < @content.length - 1 and @type isnt 'bulletlist' + # fragment.render doc, fragment.type == "para" lastType = @type - if @style.padding - doc.y += @style.padding + if @style.marginTop + doc.y += @style.marginTop + # if @style.marginLeft + # doc.x += @style.marginLeft # reads and renders a markdown/literate coffeescript file to the document render = (doc, filename) -> @@ -259,20 +209,21 @@ render = (doc, filename) -> value = meta[2] metadata[key] = value else - body += line + body += line + "\n" metadata.lastName ||= metadata.author?.split(" ").last() # console.log metadata # add header - doc.text(metadata.author, styles.meta) - doc.text(metadata.instructor, styles.meta) - doc.text(metadata.course, styles.meta) - doc.text(metadata.date, styles.meta) - doc.text(metadata.title, styles.title) + doc.text(metadata.author, _.extend({}, styles.default, styles.meta)) + doc.text(metadata.instructor, _.extend({}, styles.default, styles.meta)) + doc.text(metadata.course, _.extend({}, styles.default, styles.meta)) + doc.text(metadata.date, _.extend({}, styles.default, styles.meta)) + doc.text(metadata.title, _.extend({}, styles.default, styles.title)) tree = md.parse body - tree.shift() + console.log tree + tree.shift() # ignore 'markdown' first element while tree.length node = new Node tree.shift() @@ -292,30 +243,28 @@ render = (doc, filename) -> doc # renders the title page of the guide -renderTitlePage = (doc) -> - title = 'PDFKit Guide' - author = 'By Devon Govett' - version = 'Version ' + require('./package.json').version +# renderTitlePage = (doc) -> +# title = 'PDFKit Guide' +# author = 'By Devon Govett' +# version = 'Version ' + require('./package.json').version - doc.font 'fonts/AlegreyaSans-Light.ttf', 60 - doc.y = doc.page.height / 2 - doc.currentLineHeight() - doc.text title, align: 'center' - w = doc.widthOfString(title) +# doc.font 'fonts/AlegreyaSans-Light.ttf', 60 +# doc.y = doc.page.height / 2 - doc.currentLineHeight() +# doc.text title, align: 'center' +# w = doc.widthOfString(title) - doc.fontSize 20 - doc.y -= 10 - doc.text author, - align: 'center' - indent: w - doc.widthOfString(author) +# doc.fontSize 20 +# doc.y -= 10 +# doc.text author, +# align: 'center' +# indent: w - doc.widthOfString(author) - doc.font styles.para.font, 10 - doc.text version, - align: 'center' - indent: w - doc.widthOfString(version) +# doc.font styles.para.font, 10 +# doc.text version, +# align: 'center' +# indent: w - doc.widthOfString(version) - doc.addPage() - -renderHeader = (doc) -> +# doc.addPage() do -> doc = new PDFDocument diff --git a/guide.pdf b/guide.pdf index f3a4b616bd8c8f1372be95604fa0f371cf4b3c8b..470c3c80f48827e8945f5716ee1400322b307a4b 100644 GIT binary patch delta 3217 zcmZu!c{mhW8_$d~#vaL9V~MdfGnO%9%{I2th>&&2GLdG)pcHeFEQw)MghY`Tg+U0B zsH~A)DxqjICdSUE?)Th#zwY<`bDr}%zw>+F^PcBC=Y8{}3*@M)yI~kj2s&*MM&kqU zrkU#=Lck$#h#eSa=Nm!_4fgg8fgljS5Ca3SFVTl|G60M~&{8-kX}acz5E}m?YyM8w z+#wSLc6R?m07>HqSnfu{)iu#HH^2Y~n$`_aAD_v`LT%0Ifl*1KEHo$S~`HG4tOH<`FyukPcy$JnIj zpzamUj|}m)cv)PYy4^|=umMzq6ARyrAZ~uEZ9@Vl)MuY?E zN<-Z3u@Igi;f9g1`qFC&qIF=iuzK&5i1fqq=xg$J$Pjv^s%1(@@OqmKs_ByR_F&C>#)MO4gHXFpUfa1?RqB-|UB+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Bx-)N}29c`Z2$~E9;MO+r-JHl@TIfys6pS*$B5a+w>skf*xj5?_L_In|sL4qQ0?P z)Q-WQ9rLXHz?H6?I*aRG4)n-N#CfG|?FJwR3|1-$-9eJYwt2wao($-Tf`zYxDP&*y z)?(a*b@*%Jg)cqpvdh#ee`?jc9}SY#!iV5|Y``%D-DE>5(Y99YiWId4Gx zv^x4#)82NqGrM#K0V^9u8sXNjFP^JF|TosK*qTwF!|1ovdBlG$r;Mf0V%BuflDk^G7(2`RFqN=P0CUQyvYX9z0 z(oi|F!GG*RYW!=Ll8VNWBmScgt%CZS5ee?zes}^DgMljAdXw;QW#o}!`uh{%Du3yw iF$i$6i2hX^nPw2toj?pF;60#7loARmC1qgwJM_QM>-ro3 diff --git a/test.coffee.md b/test.coffee.md index 2e76025..f4abaa0 100644 --- a/test.coffee.md +++ b/test.coffee.md @@ -4,10 +4,13 @@ course: English 624 date: 12 February 2012 title: Toward a Recovery of Nineteenth Century Farming Handbooks -While researching texts like *Harry Potter* written about nineteenth century farming, I found a few authors who published books about the literature of nineteenth century farming, particularly agricultural journals, newspapers, pamphlets, and brochures. These authors often placed the farming literature they were studying into an historical context by discussing the important events in agriculture of the year in which the literature was published (see Demaree, for example). However, while these authors discuss journals, newspapers, pamphlets, and brochures, I could not find much discussion about another important source of farming knowledge: farming handbooks. My goal in this paper is to bring this source into the agricultural literature discussion by connecting three agricultural handbooks from the nineteenth century with nineteenth century agricultural history. +While researching texts like *Harry Potter* and *Curious George* written about **nineteenth century farming**, I found a few authors who published books about the literature of nineteenth century farming, particularly agricultural journals, newspapers, pamphlets, and brochures. These authors often placed the farming literature they were studying into an historical context by discussing the important events in agriculture of the year in which the literature was published (see Demaree, for example). However, while these authors discuss journals, newspapers, pamphlets, and brochures, I could not find much discussion about another important source of farming knowledge: farming handbooks. My goal in this paper is to bring this source into the agricultural literature discussion by connecting three agricultural handbooks from the nineteenth century with nineteenth century agricultural history. To achieve this goal, I have organized my paper into four main sections, two of which have sub-sections. In the first section, I provide an account of three important events in nineteenth century agricultural history: population and technological changes, the distribution of scientific new knowledge, and farming's influence on education. In the second section, I discuss three nineteenth century farming handbooks in connection with the important events described in the first section. I end my paper with a third section that offers research questions that could be answered in future versions of this paper and conclude with a fourth section that discusses the importance of expanding this particular project. I also include an appendix after the Works Cited that contains images of the three handbooks I examined. Before I can begin the examination of the three handbooks, however, I need to provide an historical context in which the books were written, and it is to this that I now turn. -By the 1860s, the need for this knowledge was strong enough to affect education. John Nicholson anticipated this effect in 1820 in the “Experiments” section of his book *The Farmer’s Assistant; Being a Digest of All That Relates to Agriculture and the Conducting of Rural Affairs; Alphabetically Arranged and Adapted for the United States*: +By the 1860s, the need for this knowledge was strong enough to affect education. John Nicholson anticipated this effect in 1820 in the "Experiments" section of his book *The Farmer’s Assistant; Being a Digest of All That Relates to Agriculture and the Conducting of Rural Affairs; Alphabetically Arranged and Adapted for the United States*: + > Perhaps it would be well, if some institution were devised, and supported at the expense of the State, which would be so organized as would tend most effectually to produce a due degree of emulation among Farmers, by rewards and honorary distinctions conferred by those who, by their successful experimental efforts and improvements, should render themselves duly entitled to them. (92) + +Here's my final paragraph. \ No newline at end of file