rake-templates 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 131f81f1de928bfbf9088afbbf410171059d708e
4
+ data.tar.gz: 32611bb988e4b34990c4823dd1d7844c798f13b6
5
+ SHA512:
6
+ metadata.gz: a2e4858537db722f11eb21ace22790b96b02a841881472d1d6ad28c0d24e5c95ef27b65dad0c1204a0a0b20f570e6eb446d5afed2e1a069f41c598a946992b4c
7
+ data.tar.gz: 650e6a6e99191d582798f1fb206533bd3ca2c2d8326c2e1bb06f55d64b42a3c8a8d4b6eb936a11e2f8bcd56843e90f03ce68b4a060e2c36c4bf5557b5a57db35
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rake-templates.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 myobie
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Rake::Templates
2
+
3
+ A simple templating library using rake. Assumes templates are in
4
+ `./templates` and want to be rendered into `./public`.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rake-templates'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rake-templates
21
+
22
+ ## Usage
23
+
24
+ ```sh
25
+ $ rake templates:compile
26
+ ```
27
+
28
+ will render and copy every file from `./templates` to `./public` one at
29
+ a time using tilt. The only additional method that is provided is
30
+ `asset_path` for use with [rake-sprockets](https://github.com/myobie/rake-templates).
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/myobie/rake-templates/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,56 @@
1
+ require "rake"
2
+ require "tilt"
3
+ require "rake/templates/version"
4
+ require "rake/templates/context"
5
+ load 'tasks/templates.rake'
6
+
7
+ module Rake
8
+ module Templates
9
+ module_function
10
+
11
+ def public
12
+ Pathname.new("public")
13
+ end
14
+
15
+ def all
16
+ Dir["templates/**/*"].map do |file|
17
+ path = Pathname.new(file)
18
+ next if path.directory?
19
+ next if path.to_s =~ /^_/
20
+ path
21
+ end.compact
22
+ end
23
+
24
+ def compile(file)
25
+ public.mkpath unless public.exist?
26
+
27
+ template = Tilt.new(file.to_s)
28
+ context = Context.new
29
+ rendered_content = template.render(context)
30
+ path = result_path(template)
31
+ path.open("w") do |f|
32
+ f << rendered_content
33
+ end
34
+ end
35
+
36
+ def result_path(template)
37
+ extra_endings = template.file.split(".")[2..-1].join(".")
38
+ dirname = File.dirname(template.file).gsub(/^templates/, "public")
39
+ basename = template.basename(".#{extra_endings}")
40
+ dir = Pathname.new(dirname)
41
+ dir.mkpath
42
+ dir.join(basename)
43
+ end
44
+
45
+ def compile_all
46
+ all.each do |file|
47
+ compile file
48
+ end
49
+ end
50
+
51
+ def clean
52
+ public.rmtree if public.exist?
53
+ public.mkpath unless public.exist?
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ require "rake/sprockets"
2
+
3
+ module Rake
4
+ module Templates
5
+ class Context
6
+ def asset_path(file)
7
+ Rake::Sprockets.url(file)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Rake
2
+ module Templates
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ namespace :templates do
2
+ task :compile do
3
+ Rake::Templates.compile_all
4
+ end
5
+
6
+ task :clean do
7
+ Rake::Templates.clean
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rake/templates/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rake-templates"
8
+ spec.version = Rake::Templates::VERSION
9
+ spec.authors = ["myobie"]
10
+ spec.email = ["me@nathanherald.com"]
11
+ spec.summary = %q{Simple template rendering through rake}
12
+ spec.description = %q{A small wrapper around tilt to provide templating.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+
23
+ spec.add_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "tilt", "~> 1.4"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-templates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - myobie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tilt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ description: A small wrapper around tilt to provide templating.
56
+ email:
57
+ - me@nathanherald.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rake/templates.rb
68
+ - lib/rake/templates/context.rb
69
+ - lib/rake/templates/version.rb
70
+ - lib/tasks/templates.rake
71
+ - rake-templates.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Simple template rendering through rake
96
+ test_files: []