ruby-handlebars 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +111 -2
  3. data/lib/ruby-handlebars/parser.rb +0 -1
  4. metadata +25 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4850c228d3a84c6701b524aecbb493f801bc4927
4
- data.tar.gz: d3d9abdc1cae0ab1a3625f500ec6f39a30c8cc75
3
+ metadata.gz: 151c26376bf8460ee2826d37725ab7cec3f75676
4
+ data.tar.gz: 2fa8d9952bec2bc231263ad18b4e9b3daabdeeea
5
5
  SHA512:
6
- metadata.gz: e9e72431e3c5687b375b8064dbdb99ce089d395aca63d7d0ae09f65d75742f67f9479c91a7f5ebfa0d204f957aaca7d4b468dab2325ec1238dc42ac9f624dff4
7
- data.tar.gz: c24ae4750d88e834db222b5830b242ae0a8571295aca85e3c38bc6acc895895c51f7d846608336b95573cc2304d6f784fbd3dcfe6336317d66f22cd49db2361d
6
+ metadata.gz: e322d2c6a44586ed7e28cd53176602be2b8b86b44a06f710adfd962a7ed50ae5a39fccecb8ee083850ef82be71e3a09a5a3b814e8f28880736f2f12e04c0283e
7
+ data.tar.gz: 0f46a77dce2f30aef353880f8feee1a81fef3d8dda36047e328fcdc24667882d8d32b0d6c0773fe4b2ac3f62d4d2650feeba70b800fa8bd72234c984ee80f56d
data/README.md CHANGED
@@ -1,8 +1,117 @@
1
- # ruby-handlebars
1
+ ruby-handlebars
2
+ ===============
2
3
 
3
4
  [![Build Status](https://travis-ci.org/vincent-psarga/ruby-handlebars.svg?branch=master)](https://travis-ci.org/vincent-psarga/ruby-handlebars)
4
5
  [![Code Climate](https://codeclimate.com/github/vincent-psarga/ruby-handlebars/badges/gpa.svg)](https://codeclimate.com/github/vincent-psarga/ruby-handlebars)
5
6
  [![Test Coverage](https://codeclimate.com/github/vincent-psarga/ruby-handlebars/badges/coverage.svg)](https://codeclimate.com/github/vincent-psarga/ruby-handlebars)
6
7
 
7
- Pure Ruby library for Handlebars templates.
8
+ Pure Ruby library for [Handlebars](http://handlebarsjs.com/) template system.
8
9
  The main goal of this library is to simplify the use of Ruby and Handlebars on Windows machine. If you do not have any need of working on Windows, take a look at [handlebars.rb](https://github.com/cowboyd/handlebars.rb) that uses the real Handlebars library.
10
+
11
+ Installing
12
+ ----------
13
+
14
+ Simply run:
15
+
16
+ ```shell
17
+ gem install ruby-handlebars
18
+ ```
19
+
20
+ No need for libv8, ruby-racer or any JS related tool.
21
+
22
+ Using
23
+ -----
24
+
25
+ A very simple case:
26
+
27
+ ```ruby
28
+
29
+ require 'ruby-handlebars'
30
+
31
+ hbs = Handlebars::Handlebars.new
32
+ hbs.compile("Hello {{name}}").call({name: 'world'})
33
+ # Gives: "Hello world", how original ...
34
+ ```
35
+
36
+ You can also use partials:
37
+
38
+ ```ruby
39
+ hbs.register_partial('full_name', "{{person.first_name}} {{person.last_name}}")
40
+ hbs.compile("Hello {{> full_name}}").call({person: {first_name: 'Pinkie', last_name: 'Pie'}})
41
+ # Gives: "Hello Pinkie Pie"
42
+ ```
43
+
44
+ You can also register inline helpers:
45
+
46
+ ```ruby
47
+ hbs.register_helper('strip') {|context, value| value.strip}
48
+ hbs.compile("Hello {{strip name}}").call({name: ' world '})
49
+ # Will give (again ....): "Hello world"
50
+ ```
51
+
52
+ or block helpers:
53
+
54
+ ```ruby
55
+ hbs.register_helper('comment') do |context, commenter, block|
56
+ block.fn(context).split("\n").map do |line|
57
+ "#{commenter} #{line}"
58
+ end.join("\n")
59
+ end
60
+
61
+ hbs.compile("{{#comment '//'}}My comment{{/comment}}").call
62
+ # Will give: "// My comment"
63
+ ```
64
+
65
+ Note that in any block helper you can use an ``else`` block:
66
+
67
+ ```ruby
68
+ hbs.register_helper('markdown') do |context, block, else_block|
69
+ html = md_to_html(block.fn(context))
70
+ html.nil? : else_block.fn(context) : html
71
+ end
72
+
73
+ template = [
74
+ "{{#markdown}}",
75
+ " {{ description }}",
76
+ "{{else}}",
77
+ " Description is not valid markdown, no preview available",
78
+ "{{/markdown}}"
79
+ ].join("\n")
80
+
81
+ hbs.compile(template).call({description: my_description})
82
+ # Output will depend on the validity of the 'my_description' variable
83
+ ```
84
+
85
+ Two default helpers are provided: ``each`` and ``if``. It is not yet possible to name the current item in an each loop and ``this`` must be used to reference it.
86
+
87
+ ```ruby
88
+ template = [
89
+ "{{#each items}}",
90
+ " {{{ this }}}",
91
+ "{{else}}",
92
+ " No items",
93
+ "{{/each}}",
94
+ "",
95
+ "{{#if my_condition}}",
96
+ " It's ok",
97
+ "{{else}}",
98
+ " or maybe not",
99
+ "{{/if}}",
100
+ ].join("\n")
101
+ ```
102
+
103
+ Limitations and roadmap
104
+ -----------------------
105
+
106
+ This gem does not reuse the real Handlebars code (the JS one) and not everything is handled yet (but it will be someday ;) ):
107
+
108
+ - there is no escaping, all strings are considered as safe (so ``{{{ my_var }}}`` and ``{{ my_var }}``) will output the same thing
109
+ - the parser is not fully tested yet, it may complain with spaces ...
110
+ - curly bracket are __not__ usable in the template content yet. one workaround is to create simple helpers to generate them
111
+ - parsing errors are, well, not helpful at all
112
+
113
+ Aknowledgements
114
+ ---------------
115
+
116
+ This gem would simply not exist if the handlebars team was not here. Thanks a lot for this awesome templating system.
117
+ Thanks a lot to @cowboyd for the [handlebars.rb](https://github.com/cowboyd/handlebars.rb) gem. We used it for a while and it's great (and as told at the beginning of the README, if you do not need any Windows support, use handlebars.rb instead ;) )
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  require 'parslet'
3
2
 
4
3
  module Handlebars
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-handlebars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Pretre
@@ -17,14 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 1.6.2
21
+ - - "~>"
22
+ - !ruby/object:Gem::Version
23
+ version: '1.6'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
28
  - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: '0'
30
+ version: 1.6.2
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: colorize
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -51,28 +57,40 @@ dependencies:
51
57
  requirements:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '0'
60
+ version: 0.10.1
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.10'
55
64
  type: :development
56
65
  prerelease: false
57
66
  version_requirements: !ruby/object:Gem::Requirement
58
67
  requirements:
59
68
  - - ">="
60
69
  - !ruby/object:Gem::Version
61
- version: '0'
70
+ version: 0.10.1
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.10'
62
74
  - !ruby/object:Gem::Dependency
63
75
  name: pry-stack_explorer
64
76
  requirement: !ruby/object:Gem::Requirement
65
77
  requirements:
66
78
  - - ">="
67
79
  - !ruby/object:Gem::Version
68
- version: '0'
80
+ version: 0.4.9.1
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.4'
69
84
  type: :development
70
85
  prerelease: false
71
86
  version_requirements: !ruby/object:Gem::Requirement
72
87
  requirements:
73
88
  - - ">="
74
89
  - !ruby/object:Gem::Version
75
- version: '0'
90
+ version: 0.4.9.1
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '0.4'
76
94
  - !ruby/object:Gem::Dependency
77
95
  name: rspec
78
96
  requirement: !ruby/object:Gem::Requirement