Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added thumbify

  • Loading branch information...
commit e550e135de1e04f57951432c5f21859b2dd55199 1 parent 552b508
@Trimeego Trimeego authored
View
3  .gitignore
@@ -3,3 +3,6 @@ npm-debug.log
tmp
.wikis
.DS_Store
+index.js
+experiment.js
+thumbs
View
9 Gruntfile.coffee
@@ -33,7 +33,12 @@ module.exports = (grunt) ->
gitUrl: "git@github.com:ICGGroup/grunt-wickit.wiki.git"
sitePath: "tmp/custom"
-
+ thumbify:
+ simpletest:
+ options:
+ src: "tmp/**/*.html"
+ dest: "thumbs"
+
# Unit tests.
nodeunit:
tests: ["test/*_test.coffee"]
@@ -49,7 +54,7 @@ module.exports = (grunt) ->
# Whenever the "test" task is run, first clean the "tmp" dir, then run this
# plugin's task(s), then test the result.
- grunt.registerTask "test", ["clean", "wickit", "nodeunit"]
+ grunt.registerTask "test", ["clean", "wickit", "thumbify", "nodeunit"]
# By default, lint and run all tests.
grunt.registerTask "default", ["jshint", "test"]
View
74 README.md
@@ -129,6 +129,80 @@ grunt.initConfig({
})
```
+
+## The "thumbify" task
+
+### Overview
+In your project's Gruntfile, add a section named `thumbify` to the data object passed into `grunt.initConfig()`.
+
+```js
+grunt.initConfig({
+ thumbify: {
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
+```
+
+### Options
+
+#### options.src
+Type: `files`
+
+The grunt file spec for the target files.
+
+#### options.dest
+Type: `string`
+
+The destination folder
+
+
+#### options.urlTransform
+Type: `function`
+
+A function that will be called with the file prior to rendering. This gives you an opportunity to use a local server rather than file based rendering
+
+
+### Usage Examples
+
+#### Minimum Configruation
+
+The minimum configuration is simple.
+
+```js
+grunt.initConfig({
+ thumbify: {
+ test: {
+ options: {
+ src: 'tmp/**/*.html',
+ dest: 'thumbs'
+ }
+ }
+ }
+})
+```
+
+#### Using Transform
+
+In this example, a url transformation is used to direct the rendering to an http:// page rather than a file:// reference
+
+```js
+grunt.initConfig({
+ thumbify: {
+ test: {
+ options: {
+ src: 'tmp/**/*.html',
+ dest: 'thumbs',
+ urlTransform: function(f){
+ return replace(/tmp/, "http://localhost");
+ }
+ }
+ }
+ }
+})
+```
+
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
View
127 index.js
@@ -1,127 +0,0 @@
-index = [
- {
- "id": "node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/tests/docs/W3C_Selectors.html",
- "title": "Selectors",
- "body": ""
- },
- {
- "id": "node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/tests/nwmatcher/test.html",
- "title": "NWMatcher Tests",
- "body": ""
- },
- {
- "id": "node_modules/cheerio/node_modules/cheerio-select/node_modules/CSSselect/tests/qwery/index.html",
- "title": "Qwery tests",
- "body": ""
- },
- {
- "id": "node_modules/cheerio/node_modules/htmlparser2/tests/Documents/Basic.html",
- "title": "The Title",
- "body": ""
- },
- {
- "id": "node_modules/cheerio/node_modules/underscore/index.html",
- "title": "Underscore.js",
- "body": ""
- },
- {
- "id": "node_modules/colors/example.html",
- "title": "Colors Example",
- "body": ""
- },
- {
- "id": "node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/ejs/examples/client.html",
- "title": "",
- "body": ""
- },
- {
- "id": "node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/examples/browser/test.html",
- "title": "Example tests",
- "body": ""
- },
- {
- "id": "node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/node_modules/tap/node_modules/runforcover/node_modules/bunker/node_modules/burrito/example/web/index.html",
- "title": "",
- "body": ""
- },
- {
- "id": "node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/node_modules/tap/node_modules/runforcover/node_modules/bunker/node_modules/burrito/node_modules/uglify-js/README.html",
- "title": "UglifyJS -- a JavaScript parser/compressor/beautifier",
- "body": ""
- },
- {
- "id": "node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/test/test.html",
- "title": "Nodeunit Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/colors/example.html",
- "title": "Colors Example",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test.html",
- "title": "Underscore.strings Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test_standalone.html",
- "title": "Underscore.strings Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/test/test_underscore/index.html",
- "title": "Underscore Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/index.html",
- "title": "Underscore.js",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/underscore.string/test/test.html",
- "title": "Underscore.strings Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/underscore.string/test/test_standalone.html",
- "title": "Underscore.strings Test Suite",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/underscore.string/test/test_underscore/temp_tests.html",
- "title": "Underscore Temporary Tests",
- "body": ""
- },
- {
- "id": "node_modules/grunt/node_modules/underscore.string/test/test_underscore/test.html",
- "title": "Underscore Test Suite",
- "body": ""
- },
- {
- "id": "tasks/cosmo.html",
- "title": "",
- "body": " "
- },
- {
- "id": "tasks/metro.html",
- "title": "",
- "body": " "
- },
- {
- "id": "tasks/site-dist/404.html",
- "title": "Page Not Found :(",
- "body": ""
- },
- {
- "id": "tasks/site-dist/index.html",
- "title": "",
- "body": ""
- },
- {
- "id": "tasks/template.html",
- "title": "",
- "body": " "
- }
-]
View
12 package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-wickit",
"description": "A simple plugin to generate static html from a Github wiki repo, including an index for search capability.",
- "version": "0.1.5",
+ "version": "0.1.6",
"homepage": "https://github.com/ICGGroup/grunt-wickit",
"author": {
"name": "Trimeego",
@@ -33,8 +33,12 @@
"highlight.js": "~7.3.0",
"lodash": "~1.0.1",
"cheerio": "~0.10.8",
- "colors": "~0.6.0-1"
- },
+ "colors": "~0.6.0-1",
+ "node-phantom": "~0.2.1",
+ "tmp": "0.0.16",
+ "async": "~0.2.6",
+ "imagemagick": "~0.1.3"
+ },
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
@@ -47,4 +51,4 @@
"keywords": [
"gruntplugin"
]
-}
+}
View
0  tasks/lib/thumbify.coffee
No changes.
View
1  tasks/template.html
@@ -8,7 +8,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><%=title%></title>
<meta name="description" content="">
- <meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="styles/bootstrap-theme.css">
View
70 tasks/thumbify.coffee
@@ -0,0 +1,70 @@
+path = require("path")
+fs = require("fs")
+url = require("url")
+colors = require("colors")
+phantom = require("node-phantom")
+path = require("path")
+tmp = require("tmp")
+_ = require("lodash")
+async = require("async")
+im = require("imagemagick")
+
+module.exports = (grunt) ->
+ "use strict"
+ async = grunt.util.async
+
+ grunt.registerMultiTask "thumbify", "Makes thumbnails out of html pages", ->
+ done = this.async()
+ config = grunt.config()
+ options = @options()
+ grunt.thumbifyBase = process.cwd()
+
+ tmp.dir
+ mode: 0o0750
+ prefix: "thumbify_"
+ , _tempDirCreated = (err, tempDir) ->
+ throw err if err
+
+ phantom.create (err, ph) ->
+ ph.createPage (err, page) ->
+ page.viewportSize =
+ width: 1024
+ height: 960
+
+ capturePage = (filepath, callback) ->
+ if not grunt.file.isDir(filepath)
+ filename = path.relative(path.dirname(options.src.replace('**/*', '')), filepath)
+ if options.urlTransform
+ url = options.urlTransform.apply(this, [filepath])
+ else
+ url = 'file://' + path.resolve(grunt.thumbifyBase, filepath)
+ page.open url, ->
+ output = path.resolve(tempDir, filename + ".png")
+ thumb = path.resolve(options.dest, filename + ".thumb.png")
+ grunt.file.mkdir path.dirname(path.resolve(options.dest, filename))
+
+ console.log thumb
+ console.log "capturing:" + output
+ page.render output, (err, results) ->
+ im.resize
+ srcPath: output
+ dstPath: thumb
+ width: 250
+ , (err, results) ->
+ if err
+ callback err
+ else
+ callback null, output
+ else
+ callback()
+
+ async.mapSeries grunt.file.expand(options.src), capturePage, (err, results) ->
+ console.log err, results
+ ph.exit()
+ done()
+
+
+
+
+
+
View
0  test/thumb_test.coffee
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.