ng_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 736f868d09a7035672d92d0b0f8b756717152cc8
4
+ data.tar.gz: ebd936d446402ce78fe99cb4f6a3b7fd2daa386c
5
+ SHA512:
6
+ metadata.gz: 1575cf7da2d1672e9bc120b9b434b7cefd3b089023dbb64a8790fd79d434ac1bed975167abb004e87f43011dd481158a7cea26e7b3fdf37d5327789b71a98609
7
+ data.tar.gz: 01730519be7fc50c32a2a1ea79afad8c43f297a9efde9f08e8c4510c0133bd1b854feff425f9f90f6fccd86e45f545b1dc392ad1d7b2c6ab509825947572ef0e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'NgTemplate'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,72 @@
1
+ module NgTemplate
2
+ #
3
+ # Helper to render angularjs templates as partials
4
+ #
5
+ # USAGE
6
+ # class ApplicationController
7
+ # helper NgTemplate::TemplateHelper
8
+ # ...
9
+ # end
10
+ module TemplateHelper
11
+ class TemplateRenderer
12
+ def initialize(view_ctx, paths, opt = {})
13
+ @view_ctx = view_ctx
14
+ @paths = Array(paths)
15
+ @opt = {
16
+ mode: Rails.configuration.ng_template.mode,
17
+ prefix: Rails.configuration.ng_template.prefix,
18
+ }.merge!(opt)
19
+ end
20
+
21
+ #
22
+ # @return html-safe-template
23
+ #
24
+ def render
25
+ templates = @view_ctx.view_paths.map do |view_path|
26
+ @paths.map do |path|
27
+ render_path(view_path, path)
28
+ end
29
+ end
30
+
31
+ templates.flatten.compact.map do |template|
32
+ render_html(template)
33
+ end.join("\n").html_safe
34
+ end
35
+
36
+ private
37
+
38
+ def render_html(template)
39
+ "<script type='text/ng-template' id='#{template[:name]}'>\n#{template[:content]}\n</script>"
40
+ end
41
+
42
+ #
43
+ # @return [{name: template-name, content: template}, ...]
44
+ #
45
+ def render_path(view_path, path)
46
+ Dir["#{view_path}/#{path}/#{@opt[:prefix]}*.html*"].map do |file_path|
47
+ name = File.basename(file_path)
48
+ partial_name = path + "/" + name[1, name.index('.') - 1]
49
+ {
50
+ name: partial_name,
51
+ content: render_template(partial_name),
52
+ }
53
+ end
54
+ end
55
+
56
+ #
57
+ # @param partial_name template partial name
58
+ # @return template content
59
+ #
60
+ def render_template(partial_name)
61
+ @view_ctx.render partial_name
62
+ end
63
+ end
64
+
65
+ #
66
+ # Render all templates in given path
67
+ #
68
+ def ng_template_include(paths)
69
+ TemplateRenderer.new(self, paths).render
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ module NgTemplate
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace NgTemplate
4
+
5
+ initializer 'ng_template init' do
6
+ config.ng_template = ActiveSupport::OrderedOptions.new
7
+ config.ng_template.mode = :html
8
+ config.ng_template.prefix = '_'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module NgTemplate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "ng_template/engine"
2
+
3
+ module NgTemplate
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ng_template do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ng_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kari Ikonen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Manage AngularJS templates as HTML partials
42
+ email:
43
+ - mr.kari.ikonen@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - app/helpers/ng_template/template_helper.rb
51
+ - lib/ng_template.rb
52
+ - lib/ng_template/engine.rb
53
+ - lib/ng_template/version.rb
54
+ - lib/tasks/ng_template_tasks.rake
55
+ homepage: https://github.com/kikonen/ng_template
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: AngularJS template handler for Rails
79
+ test_files: []
80
+ has_rdoc: