templates 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/Rakefile +2 -0
- data/app/controllers/templates/templates_controller.rb +60 -0
- data/lib/templates/action_controller.rb +21 -0
- data/lib/templates/engine.rb +8 -0
- data/lib/templates/version.rb +3 -0
- data/lib/templates.rb +2 -0
- data/templates.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Templates
|
2
|
+
class TemplatesController < ApplicationController
|
3
|
+
unloadable
|
4
|
+
|
5
|
+
def index
|
6
|
+
render :json => collect_templates
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def collect_templates
|
12
|
+
|
13
|
+
app_templates = {}
|
14
|
+
|
15
|
+
Dir.new("#{RAILS_ROOT}/app/controllers").entries.each do |controller_file_name|
|
16
|
+
|
17
|
+
if controller_file_name =~ /_controller/
|
18
|
+
controller_name = controller_file_name.camelize.gsub('.rb', '')
|
19
|
+
|
20
|
+
if controller_name != 'ApplicationController'
|
21
|
+
|
22
|
+
controller = controller_name.constantize
|
23
|
+
templates_hash = {}
|
24
|
+
|
25
|
+
unless controller.templates_options.nil?
|
26
|
+
|
27
|
+
if controller.templates_options[:layout]
|
28
|
+
templates_hash[:layout] = render_to_string(:file => "layouts/#{controller.controller_name}", :layout => false)
|
29
|
+
end
|
30
|
+
|
31
|
+
if controller.templates_options[:partials].count > 0
|
32
|
+
|
33
|
+
templates_hash[:partials] = {}
|
34
|
+
|
35
|
+
controller.templates_options[:partials].each do |partial|
|
36
|
+
templates_hash[:partials][partial] = render_to_string(:file => "#{controller.controller_name}/_#{partial}", :layout => false)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
if not controller.templates_list.nil? and controller.templates_list.count > 0
|
43
|
+
|
44
|
+
templates_hash[:templates] = {}
|
45
|
+
|
46
|
+
controller.templates_list.each do |template|
|
47
|
+
templates_hash[:templates][template] = render_to_string(:file => "#{controller.controller_name}/#{template}", :layout => false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
app_templates[controller.controller_name] = templates_hash unless templates_hash.empty?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
app_templates
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Templates
|
2
|
+
module ActionController
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
class_attribute :templates_list, :templates_options
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def templates list, options = {}
|
11
|
+
self.templates_list = list
|
12
|
+
self.templates_options = { :partials => [], :layout => false }.merge(options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ActionController::Base
|
19
|
+
include Templates::ActionController
|
20
|
+
end
|
21
|
+
|
data/lib/templates.rb
ADDED
data/templates.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "templates/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "templates"
|
7
|
+
s.version = Templates::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Sasha Koss']
|
10
|
+
s.email = ['kossnocorp@gmail.com']
|
11
|
+
s.homepage = ''
|
12
|
+
s.summary = %q{Rails engine which render selected templates to json}
|
13
|
+
s.description = %q{Rails engine which render selected templates to json}
|
14
|
+
|
15
|
+
s.rubyforge_project = "templates"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: templates
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sasha Koss
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-02 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Rails engine which render selected templates to json
|
22
|
+
email:
|
23
|
+
- kossnocorp@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Rakefile
|
34
|
+
- app/controllers/templates/templates_controller.rb
|
35
|
+
- lib/templates.rb
|
36
|
+
- lib/templates/action_controller.rb
|
37
|
+
- lib/templates/engine.rb
|
38
|
+
- lib/templates/version.rb
|
39
|
+
- templates.gemspec
|
40
|
+
homepage: ""
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: templates
|
69
|
+
rubygems_version: 1.7.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Rails engine which render selected templates to json
|
73
|
+
test_files: []
|
74
|
+
|