Code Monkey home page Code Monkey logo

grunt-codekit's Introduction

grunt-codekit

Grunt plugin for compiling Kit files Can be used to embed files or concatenate files

NPM version Build Status

Getting Started

Install the plugin

npm install grunt-codekit --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-codekit');

Choose files to compile

The plugin supports compiling templates written using the Kit language of CodeKit™. You can use both short form and long form when specifying input and output destination.

Using short form (see below), the output files will be placed in the dest directory and have the same names as the input files, only using a .html extension. When using the long form you can explicitly specify the full name and path of each output file.

There is nothing in the way of mixing and matching the two styles.

Configuration options

As with all Grunt plugins, you can specify an options object, either for all tasks or for each task. There is currently just one option:

  • compilePrefixed - Files starting with an underscore (such as _header.kit), so called partials, are normally not considered for compilation. By setting this option to true you can override this setting and still compile these files (default false).

Do remember that Grunt has a [lot of fancy ways of doing file system manipulation] (http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically) for you

Example configuration

grunt.initConfig({
  codekit: {
  
    globbed_example_config : {
        src : 'templates/**/*.kit',
        dest : 'build/html/'
    },
    
    explicit_output_names: {
      files : {
        'build/index.html' : '/templates/my_special_index.kit'
      }
    },
    
    build_with_underscored_files : {
        options : { compilePrefixed : true },
        files : {
            'build/about.html' : '_about.kit',
            'build/index.html' : '_index.kit'
        }
    },

    // see http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
    dynamic_file_object: {
        files: [{
            expand: true,
            cwd: 'sources',
            src: ['**/*.kit'],
            dest: 'build',
            ext: '.html'
    }
});

Example usage: embedding critical path CSS

Using Penthouse one can generate a file containing the critical path css, which can dramatically impact your site's perceived speed and your page ranking in Google.

You still need a way of embedding that CSS, though, and one way of doing that is using the Kit language. An example on how this kit file might look is as follows

<html>
<head>
<title><!-- @title --></title>

<!-- embed critical path css generated by penthouse -->
<style>
<!--@include critical.css -->
</style>

</head>
<body>
    <!-- @include _header.kit -->
    <!-- @include _navbar.kit -->
    The main text of the page
    <!-- @include _footer.kit -->
</body>
</html>

About the Kit language

The Kit language is a simple html templating language used in the commercial program CodeKit. It imports files into other html files and does simple variable substitution. Since Bryan Jones made it open source it has seen support from several other programs, among those PrePros and implementations in Python and Javascript. This plugin makes it possible to compile these files using Grunt.

Release History

  • 0.1.0 First release. Compilation of Kit files using an embedded python module.
  • 0.2.0 Removed dependency on Python.
  • 0.3.0 Partials are now being excluded.
  • 0.4.0 Added support for CodeKit/PrePros javascript concatenation directives.
  • 1.0.0 Added globbing support and removed support for javascript compilation.

grunt-codekit's People

Contributors

aral avatar fatso83 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

grunt-codekit's Issues

Unable to launch in a watch task

Grunt stopped as soon as it execute and no other tasks can be ran :(

grunt.registerTask('default', ['codekit:default', 'copy', 'sass:watch', 'concat:watch', 'uglify:watch', 'imagemin:watch', 'connect', 'open', 'watch']);

HTML file has a lot of white space at top

When the html file is generated from my kit files, there are 10 - 13 lines of whitespace before the first line of html.

I noticed that most of the files start at line #13, but some start at #10.

I looked at the master template and see that line #10 is the first line where a variable is referenced, and #13 is the second.

-- Scott
kit-files

Variables from Imported Files

It seems grunt-codekit does not recognise Variables from imported file. Codekit app does. Assuming this scenario:
I have two files path.kit containing:
<!--@path_img : assets/css/-->

Import path.kit in index.kit and use the variable:
<!-- @include "path.kit" -->
<img src="<!--@path_img-->/style.css"/>

This throws an error: The variable @path_img is undefined.

Task freezes

Hi

I'm trying to use grunt-codekit only with html file (3 kit files -> 1 html).

But it freezes on line 91.

Version of grunt-codekit is 0.4.0

P.S. I found how to fix it. Just added done() after line 91. But I'm not sure will it work with all other stuff.

Regards, Roman

Feature Request: not require listing of each .kit file

I've been using version 0.3.1, but didn't like having to list each .kit file AND the .html version. I wanted, instead, to point to the directory where the .kit files are stored, and specify an output directory where the html files would be placed.

In version 0.3.1, I found, I could do this if I replaced a single line of code:

// (line 62) grunt.file.write(destination, html );
grunt.file.write(path.resolve(destination, path.basename(filepath, '.kit') + '.html'), html );

Then, I could adjust my Gruntfile.js to:

codekit: {
    dev: {
          src: ['src/codekit_src/*.kit'],
          dest: 'output'
    }
},

Et Voila! C'est manifique! The 'output' folder is filled with lovely html files.

However, I just tried to upgrade to 0.4.x and found I can no longer do this as you've traveled further down the one-file-at-a time implementation with hard-coded f.src[0] references.

I tried to change line 78 to:

 // line 78 var filepath = f.src[0];
 var src = f.src.filter(function(filepath) {
    // wrapping all of the file extension matching code
    /// btw, was there really a need to process .js files??? 
      ///   perhaps js bundling can be forked into another project?
 }

The problem is that since the task is assuming we're working on a single file, the compileKitFile() function calls callback() which is designed to only be called once after everything has been processed. The result is that the second file to be processed generates an error.

I tried taking out the callback() call, but the grunt task hangs and never finishes. I don't have enough experience with this stuff to know how to handle this

I guess, I'll just downgrade to 0.3.1 for now and manually change the task file.

Thanks,
Scott

Support for @codekit-prepend/append

Hello,

I found in your blog and in the commit history that you added and then removed support for @codekit-prepend/append. Can you tell me a bit more about that change? Do you have any recommendation on how to handle those imports in grunt?

Thank you

Counter-intuitive configuration

My uglify configuration:
'build/javascripts/app.min.js': ['build/javascripts/app.min.js']
My sass configuration:
"develop/stylesheet/screen.scss": "build/css/screen.css"
My codekit configuration:
'build/index.html': 'develop/index.kit'

Please note that, apart from your plugin, it's always 'from': 'to'. Your plugin uses 'to': 'from' format. I think we should follow the standard here.


Great job Carl-Erik! Thanks for this plugin, made my transition to grunt much easier.

npm install fails on windows

npm install fails on windows,
it seems it is because of only unix like execution method

[email protected] preinstall H:\Users\Beliczki\node_modules\grunt-codekit
./python_dependency_checker.js

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! [email protected] preinstall: ./python_dependency_checker.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the grunt-codekit package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./python_dependency_checker.js
npm ERR! You can get their info via:
npm ERR! npm owner ls grunt-codekit
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "H:\Program Files\nodejs\node.exe" "H:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "grunt-codekit" "--save-dev"
npm ERR! cwd H:\Users\Beliczki
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! H:\Users\Beliczki\npm-debug.log
npm ERR! not ok code 0

Glob pattern working with 0.5.2 breaks in 1.0.0-beta

    codekit:
      all:
        files: [{
          expand: true
          cwd: 'source/'
          src: ['**/*.html']
          dest: 'build'
          ext: '.html'
        }]

Will look into it when I get a moment but wanted to document it. Must be due to new glob handling. (We use .html as the extension for kit files for template preview — probably also related to grunt-codekit not expecting that.)

Sample error:

Running "codekit:all" (codekit) task
Warning: Unable to write "/Users/aral/ind.ie/projects/site/build/404/index.html/index.html.html" file (Error code: ENOTDIR). Use --force to continue.

Meta tags containing variable content aren't getting closed properly

I'm trying to use variables to place things like text, urls, markup, etc. CodeKit builds these things just fine, but grunt-codekit is terminating the line such that the meta tags aren't being properly closed.

Given these page-level variables:

<!-- $twitterDesc = twitterDescription lorem ipsum -->


<!-- $canonicalUrl = http://www.example.com/index.html -->

And this master template:

<meta name="twitter:description" content="">


<meta property="og:url" content="">

The output is below. Note the missing ">

<meta name="twitter:description" content="twitterDescription lorem ipsum


<meta property="og:url" content="http://www.example.com/index.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.