rcurse 0.2.5 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5af5099ed61ed119a867af78807019a7d52c7a77
4
- data.tar.gz: bc9020f6c1d647b2b4962b795f7996424f0f5466
3
+ metadata.gz: c26d197807ffb34df4ef372293e0636708865057
4
+ data.tar.gz: 05e62ada8b1954a4ee5bb326664fdeb199f2f232
5
5
  SHA512:
6
- metadata.gz: d747006f020d4b609a103918fb079f200494e9fb053ace280a265660a4fc545d1b20834888287d3a7e04781395fa6821273fff0724dd9264b81dfb07985e59ae
7
- data.tar.gz: 47be8a207198a419858e9156e5890f302cdf0d47764e525c50a0b84344936de6abce68988fb52443302858a249f1ff7fa7bf92ef67efe3ef1fde6b49443b0491
6
+ metadata.gz: c88ae712a7d591f8ff212d0296fb4c62a6dc74ddccbe1a0c37da0f4943698dec8f084e7f24edaa54b808d2fef9c574fa6168cecfea33612a42d4c6063e8be444
7
+ data.tar.gz: 77122d9d2e900d5f4d98f2d0dfeba000d54aa7f0d7eeb7be7642f4ecad191e11616cc987bee345a977f5c5fca988f305c9cd7a794e2fd25d7d3a644eb3ef1e2c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Nick Shvelidze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,42 @@
1
1
  # Rcurse <small>- Super simple template engine</small>
2
2
 
3
- Currently WIP
3
+ ## Installation
4
+
5
+ Install it with `gem install rcurse`,
6
+
7
+ ### Using Bundler
8
+
9
+ add `gem :rcurse` to your `Gemfile` and run `bundle install`
10
+
11
+ ## Usage
12
+
13
+ Require it with `require 'rcurse'`.
14
+ Call `Rcurse.render "file.rcurse"` to render `file.rcurse` and return the rendered file contents, you can then write it to a file.
15
+
16
+ ### Complete example
17
+
18
+ Let's assume that we have file names `index.rcurse` and want to render it to `index.html`
19
+
20
+ ```ruby
21
+ require 'rcurse'
22
+ Rcurse.render_file("index.rcurse", "index.html")
23
+ ```
24
+
25
+ ## Helpers
26
+
27
+ Helpers are the only functionality Rcurse provides yet. Use them by inserting `{{helper-name arguments}}` in source files.
28
+
29
+ ### Builtin helpers
30
+ - `include filename` - include another file, like so: `{{include header.rcurse}}`
31
+
32
+ ### Adding a helper
33
+
34
+ Use `Rcurse::Helper.new(name) { block }` to create a helper, your block can accept a single array of arguments.
35
+ Use `Rcurse.add_helper(helper)` to add your helper to Rcurse.
36
+
37
+ ```ruby
38
+ my_helper = Rcurse::Helper.new("my_helper") do |arguments|
39
+ # do something with arguments and return a string containing the new content
40
+ end
41
+ Rcurse.add_helper(my_helper)
42
+ ```
@@ -9,9 +9,8 @@ module Rcurse
9
9
  @helpers
10
10
  end
11
11
 
12
- def self.render filename
13
- file_contents = File.read filename
14
- file_contents.gsub /{{([^ ]+) *(.+)?}}/ do |s|
12
+ def self.render content
13
+ content.gsub /{{([^ ]+) *(.+)?}}/ do |s|
15
14
  name = $1
16
15
  args = $2 ? $2.split(" ") : []
17
16
  if @helpers[name].is_a? Rcurse::Helper then
@@ -19,4 +18,12 @@ module Rcurse
19
18
  end
20
19
  end
21
20
  end
22
- end
21
+
22
+ def self.render_file filename, out_filename
23
+ content = File.read(filename)
24
+ rendered_content = self.render(content)
25
+ File.open(out_filename, "w+") do |file|
26
+ file.write(rendered_content)
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  Rcurse.add_helper(Rcurse::Helper.new("include") do |args|
2
- Rcurse::render args[0]
2
+ Rcurse::render File.read(args[0])
3
3
  end)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rcurse'
3
- s.version = '0.2.5'
3
+ s.version = '0.3.1'
4
4
  s.licenses = ['MIT']
5
5
  s.summary = "Super simple template engine."
6
6
  s.description = "Super simple template engine."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Shvelidze
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - .gitignore
20
20
  - Gemfile
21
+ - LICENSE
21
22
  - README.md
22
23
  - lib/rcurse.rb
23
24
  - lib/rcurse/engine.rb