barber 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
- # Handlebars::Precompiler
1
+ # Barber
2
2
 
3
- TODO: Write a gem description
3
+ Barber handles all your Handlebars precompilation needs. You can use
4
+ Barber as part of your project build system or with someting like
5
+ [rake-pipeline](https://github.com/living-social/rake-pipeline).
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'handlebars-precompiler'
11
+ gem 'barber'
10
12
 
11
13
  And then execute:
12
14
 
@@ -14,11 +16,77 @@ And then execute:
14
16
 
15
17
  Or install it yourself as:
16
18
 
17
- $ gem install handlebars-precompiler
19
+ $ gem install barber
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ You will mainly interact with the utility classes. The utitlity classes
24
+ delegate to the actual precompiler. They support two primary use cases:
25
+
26
+ 1. Precompiling individual handlebars files.
27
+ 2. Precompiling inline handlebars templates.
28
+
29
+ Here are some code examples:
30
+
31
+ ```ruby
32
+ require 'barber'
33
+
34
+ Barber::FilePrecompiler.call(File.read("template.handlebars"))
35
+ # "Handlebars.template(function(...));"
36
+
37
+ Barber::InlinePreCompiler.call(File.read("template.handlebars"))
38
+ # Note the missing semicolon. You can use this with gsub to replace
39
+ # calls to inline templates
40
+ # "Handlebars.template(function(...))"
41
+ ```
42
+
43
+ Barber also packages Ember precompilers.
44
+
45
+ ```ruby
46
+ require 'barber'
47
+
48
+ Barber::Ember::FilePrecompiler.call(File.read("template.handlebars"))
49
+ # "Ember.Handlebars.template(function(...));"
50
+
51
+ Barber::Ember::InlinePrecompiler.call(File.read("template.handlebars"))
52
+ # "Ember.Handlebars.template(function(...))"
53
+ ```
54
+
55
+ ## Building Custom Precompilers
56
+
57
+ All of Barber's utility classes (demoed above) delegate to
58
+ `Barber::Precompiler`. `Barber::Precompiler` implements a simple public
59
+ interface you can use to to build your own. A precompiler simply exposes
60
+ a `Barber.precompile` JS property. Override
61
+ `Barber::Precompiler#sources` to setup your own. Source must respond to
62
+ `#read`. Here is an example:
63
+
64
+ ```ruby
65
+ require 'barber'
66
+ require 'stringio'
67
+
68
+ class CustomPrecompiler < Barber::Precompiler
69
+ def sources
70
+ [StringIO.new(custom_compiler)]
71
+ end
72
+
73
+ def custom_compiler
74
+ %Q[var Barber = { precompile: function(template) { return "Hello World!" } };]
75
+ end
76
+ end
77
+ ```
78
+
79
+ ## Usage with rake-pipeline-web-filters
80
+
81
+ All the utility classes implement `call`. This means they can be
82
+ subsituted for procs/lambda where needed. Here's how you can get
83
+ precompilation of your ember templates with rake-pipeline-web-filters:
84
+
85
+ ```ruby
86
+ match "**/*.handlebars" do
87
+ handlebars :wrapper_proc => Barber::Ember::FilePrecompiler
88
+ end
89
+ ```
22
90
 
23
91
  ## Contributing
24
92
 
@@ -1,16 +1,16 @@
1
1
  module Barber
2
2
  module Ember
3
3
  class Precompiler < Barber::Precompiler
4
- def ember_path
5
- @ember_path ||= File.new(File.expand_path("../../javascripts/ember.js", __FILE__))
4
+ def ember
5
+ @ember ||= File.new(File.expand_path("../../javascripts/ember.js", __FILE__))
6
6
  end
7
7
 
8
- def precompiler_path
9
- @precompiler_path = File.new(File.expand_path("../../javascripts/ember_precompiler.js", __FILE__))
8
+ def precompiler
9
+ @precompiler = File.new(File.expand_path("../../javascripts/ember_precompiler.js", __FILE__))
10
10
  end
11
11
 
12
12
  def sources
13
- super + [File.new(ember_path), File.new(precompiler_path)]
13
+ super << ember
14
14
  end
15
15
  end
16
16
  end
@@ -28,16 +28,16 @@ module Barber
28
28
  end
29
29
 
30
30
  def sources
31
- [precompiler_path, handlebars_path]
31
+ [precompiler, handlebars]
32
32
  end
33
33
 
34
- def handlebars_path
35
- @handlebears_path ||= File.new(File.expand_path("../javascripts/handlebars.js", __FILE__))
34
+ def handlebars
35
+ @handlebears ||= File.new(File.expand_path("../javascripts/handlebars.js", __FILE__))
36
36
  end
37
37
 
38
38
  private
39
- def precompiler_path
40
- @precompiler_path ||= File.new(File.expand_path("../javascripts/handlebars_precompiler.js", __FILE__))
39
+ def precompiler
40
+ @precompiler ||= File.new(File.expand_path("../javascripts/handlebars_precompiler.js", __FILE__))
41
41
  end
42
42
 
43
43
  def context
@@ -1,3 +1,3 @@
1
1
  module Barber
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 2188144724700774625
121
+ hash: -180034689176521228
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 2188144724700774625
130
+ hash: -180034689176521228
131
131
  requirements: []
132
132
  rubyforge_project:
133
133
  rubygems_version: 1.8.23