GitXplorerGitXplorer
t

barber

public
44 stars
27 forks
0 issues

Commits

List of commits on branch master.
Verified
155929e89410e3692e008db05ce9b54c54f36cac

Bump version to 0.12.2

ttricknotes committed 6 years ago
Verified
d73441d677596848361a711111d302a3fd7c366c

Merge pull request #68 from bradleypriest/patch-1

ttricknotes committed 6 years ago
Verified
4479f2e315e05fe4fcaaa2446c001bbf3318b922

Add license to gemspec for easier automatic discovery

bbradleypriest committed 6 years ago
Verified
234773f913de5aceeeb1c9ac52b767b89b7794da

Bump version to 0.12.1

ttricknotes committed 6 years ago
Verified
6297da4e88043c7d406d87f3be28643fba24006f

Merge pull request #67 from tricknotes/allow-handlebars-source-4.1

ttricknotes committed 6 years ago
Verified
b23137ade30918e5379076527de65a62f9092e8c

Allow handlebars-source 4.1

ttricknotes committed 6 years ago

README

The README file for this repository.

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