Giter Club home page Giter Club logo

barber's Introduction

Barber Build Status

Barber handles all your Handlebars precompilation needs. You can use Barber as part of your project build system or with someting like rake-pipeline.

Installation

Add this line to your application's Gemfile:

gem 'barber'

And then execute:

$ bundle

Or install it yourself as:

$ gem install barber

Usage

You will mainly interact with the utility classes. The utitlity classes delegate to the actual precompiler. They support two primary use cases:

  1. Precompiling individual handlebars files.
  2. Precompiling inline handlebars templates.

Here are some code examples:

require 'barber'

Barber::FilePrecompiler.call(File.read("template.handlebars"))
# "Handlebars.template(function(...));"

Barber::InlinePrecompiler.call(File.read("template.handlebars"))
# Note the missing semicolon. You can use this with gsub to replace
# calls to inline templates
# "Handlebars.template(function(...))"

Barber also packages Ember precompilers.

require 'barber'

Barber::Ember::FilePrecompiler.call(File.read("template.handlebars"))
# "Ember.Handlebars.template(function(...));"

Barber::Ember::InlinePrecompiler.call(File.read("template.handlebars"))
# "Ember.Handlebars.template(function(...))"

Building Custom Precompilers

All of Barber's utility classes (demoed above) delegate to Barber::Precompiler. Barber::Precompiler implements a simple public interface you can use to to build your own. A precompiler simply exposes a Barber.precompile JS property. Override Barber::Precompiler#sources to setup your own. Source must respond to #read. Here is an example:

require 'barber'
require 'stringio'

class CustomPrecompiler < Barber::Precompiler
  def sources
    [StringIO.new(custom_compiler)]
  end

  def custom_compiler
    %Q[var Barber = { precompile: function(template) { return "Hello World!" } };]
  end
end

Usage with rake-pipeline-web-filters

All the utility classes implement call. This means they can be subsituted for procs/lambda where needed. Here's how you can get precompilation of your ember templates with rake-pipeline-web-filters:

require 'barber'

match "**/*.handlebars" do
  handlebars :wrapper_proc => Barber::Ember::FilePrecompiler
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

barber's People

Contributors

ahawkins avatar bradleypriest avatar cowboyd avatar formigarafa avatar hrysd avatar ianpetzer avatar machty avatar minusfive avatar pootsbook avatar tchak avatar tricknotes 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

Watchers

 avatar  avatar  avatar  avatar  avatar

barber's Issues

Barber::PrecompilerError with handlebars 1.1.1

Hi, is emblem.js/barber currently supposed to work with handlebars 1.1.1/2?

I'm seeing this

Pre compilation failed for: = outlet

. Compiler said: TypeError: Cannot read property '3' of undefined
  (in ../assets/javascripts/templates/account.js.emblem)

but I'm unsure how to diagnose it further, as there's no "3" close to that context.
Maybe it's an emblem issue? I opened a similar question there.

Update Gem

I was wondering if it would be possible to release an update of the gem including Handlebars RC4? I believe I'm getting the same problem as emberjs/ember-rails#135, except for RC4.

I'm trying to use rails g ember:install --head with ember-rails and I end up getting this error:

Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 1.0.0-rc.4) or downgrade your runtime to an older version (== 1.0.0-rc.3). 

Thanks

Add support for HTMLBars

With HTMLBars' release imminent, it'll be helpful to add precompiler support so folks who use ember-rails can start testing their apps.

@tchak adding support doesn't look crazy, but I'm still trying to grok how this library works. I can probably put together a pull request with a nudge in the right direction...

Retaining directory name for compiled Ember templates

I have been using Barber to successfully pre-compile my Ember templates, but I am now trying to add resources to my Ember Routing. This means that the templates need to be named 'resource/route'. I have created the correct folders but the EmberPreCompiler ignores the folder and simply names the compiled Ember template according to the name.

Currently a file called /post/details.hbs will precompile to Ember.TEMPLATES['details'] but I need to precompile to Ember.TEMPLATES['post/details']

Is there any way to do this?

HTML comments shouldn't be parsed when pre-compiling templates

I'm using ember-rails to precompile Handlebars templates for our Ember.js app and noticed that HTML comments are being parsed in templates.

This causes Ember to throw the following error if Handlebars tags are present in a comment: "Cannot perform operations on a Metamorph that is not in the DOM."

Here's a snippet from a precompiled template:

data.buffer.push("<!-- ");
hashTypes = {};
stack1 = helpers['if'].call(depth0, "open", {hash:{},inverse:self.program(5, program5, data),fn:self.program(3, program3, data),contexts:[depth0],types:["ID"],hashTypes:hashTypes,data:data});
if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
data.buffer.push(" -->\n");

The expected output would be to have the whole comment pushed verbatim to the buffer.

Thanks!

Patch release?

Can we get a patch release? v0.4.2 will bomb out when an empty string is passed for compilation. master branch is OK. I didn't investigate further to determine if the issue was resolved in Barber or upstream in Handlebars itself. in https://github.com/dockyard/ember-appkit-rails we are generating empty templates by default and the current version of Barber is causing the app to blow up. I'm considering this a blocking issue for the v0.2.0 release of our gem.

Now it is hardly what supporting both Ember.js and raw Handlebars

barber is awesome project for Handlebars precompilation in Ruby world.

Otherwise, Ember.js 1.10.0 uses HTMLBars instead of Handlebars.
So it makes hardly to maintain both supporting compilation for Ember.js and raw Handlebars. (such as #33 )

@tchak
If you don't mind, could you consider extracting Emebr specific code from barber?
(or make barber Ember specific compiler.)

If you would agree with me, I'll work for it .

How to compile against specific versions of Ember with Barber

Currently I'm using barber 0.3.0, my Gemfile looks like

gem 'barber', "~> 0.3.0"

I'd like to update my ember source to 1.0.0-rc.2,
I've seen that ember-source and handlebars-source are dependencies of barber,
But how should I compile against a specific version of Ember(1.0.0-rc.2) and Handlebars(1.0.0-rc.3) with Barber

Handlebars 1.1.2

Hi!

Is there anything preventing barber to use handlebars 1.1.2? I think I have a bug in my ember.js application that may be solved by updating handlebars, but I can't since I depend on ember-rails, which depends on barber.

If there's no compelling reason, may I send some PR's to those projects? (knowing that @tchak maintains both of them).

Thanks!

Installation of v0.4.0 fails due to invalid dependency

I tried to install barber but it erred because it couldn't resolve the dependencies. Installing the previous version 0.3.0 works:

$ gem install barber -v 0.3.0
Fetching: barber-0.3.0.gem (100%)
Successfully installed barber-0.3.0
1 gem installed
$ gem install barber -v 0.4.1
ERROR:  While executing gem ... (Gem::DependencyError)
    Unable to resolve dependencies: barber requires ember-template-compiler-source (>= 0)

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.