diorama 0.1.0

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: 75daa5cd5cffac29998a4e7f76ce2fa4c3a3baeb
4
+ data.tar.gz: 5053181193f8f9a94bf5fee1d94e4632d3828c3b
5
+ SHA512:
6
+ metadata.gz: 05c08f1b829d195f2e4d4e94b00e7b06b6a967e3dad40dd80fe80f5f24d567d22406ddab19fae5053e010ba7d90936e4f438df98fbd6a08f2dd33c63b8a0a033
7
+ data.tar.gz: 5fa4661e141e05de2d07429066f23ea65c7ef8a42214a70e35f80f868962c73b6541750e7180ed186c163f1c536f092f211316608889d5fa9ca5ccf59f4eb156
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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Diorama
2
+ A Ruby Gem which allows a Rails app to use view templates from the database.
3
+
4
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Diorama'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
data/lib/diorama.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'diorama/resolver'
2
+ require 'diorama/orm_extender'
@@ -0,0 +1,31 @@
1
+ module Diorama
2
+ module Orm
3
+ module ActiveRecord
4
+ def stores_diorama_templates
5
+ class_eval do
6
+ validates :body, :presence => true
7
+ validates :path, :presence => true
8
+ validates :format, :inclusion => Mime::SET.symbols.map(&:to_s)
9
+ validates :locale, :inclusion => I18n.available_locales.map(&:to_s), :allow_blank => true
10
+ validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)
11
+
12
+ after_save { Diorama::Resolver.instance.clear_cache }
13
+
14
+ extend ClassMethods
15
+ end
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+ def find_model_templates(conditions = {})
21
+ self.where(conditions)
22
+ end
23
+
24
+ def resolver(options = {})
25
+ Diorama::Resolver.using self, options
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ ActiveRecord::Base.extend Diorama::Orm::ActiveRecord
@@ -0,0 +1,60 @@
1
+ module Diorama
2
+ class Resolver < ActionView::Resolver
3
+ require 'singleton'
4
+ include Singleton
5
+
6
+ def find_templates(name, prefix, partial, details)
7
+ return [] if @@resolver_options[:only] && !@@resolver_options[:only].include?(prefix)
8
+ conditions = {
9
+ :path => normalize_path(name, prefix),
10
+ :locale => normalize_array(details[:locale]),
11
+ :format => normalize_array(details[:formats]),
12
+ :handler => normalize_array(details[:handlers]),
13
+ :partial => partial || false
14
+ }
15
+
16
+ result = @@model.where(conditions).map do |record|
17
+ initialize_template(record)
18
+ end
19
+
20
+ return result
21
+ end
22
+
23
+ def self.using(model, options = {})
24
+ @@model = model
25
+ @@resolver_options = options
26
+ self.instance
27
+ end
28
+
29
+ def normalize_path(name, prefix)
30
+ prefix.present? ? "#{prefix}/#{name}" : name
31
+ end
32
+
33
+ def normalize_array(array)
34
+ array.map(&:to_s)
35
+ end
36
+
37
+ def initialize_template(record)
38
+ source = record.body
39
+ identifier = "SqlTemplate - #{record.id} - #{record.path.inspect}"
40
+ handler = ActionView::Template.registered_template_handler(record.handler)
41
+
42
+ details = {
43
+ :format => Mime[record.format],
44
+ :updated_at => record.updated_at,
45
+ :virtual_path => virtual_path(record.path, record.partial)
46
+ }
47
+
48
+ ActionView::Template.new(source, identifier, handler, details)
49
+ end
50
+
51
+ def virtual_path(path, partial)
52
+ return path unless partial
53
+ if index = path.rindex('/')
54
+ path.insert(index + 1, '_')
55
+ else
56
+ "_#{path}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Diorama
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :diorama do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diorama
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-18 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: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_girl
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ description: This Gem allows Rails applications to store it's view templates in it's
112
+ database.
113
+ email:
114
+ - david@softwareblacksmith.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - MIT-LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - lib/diorama.rb
123
+ - lib/diorama/orm_extender.rb
124
+ - lib/diorama/resolver.rb
125
+ - lib/diorama/version.rb
126
+ - lib/tasks/diorama_tasks.rake
127
+ homepage: https://github.com/anotherdjohnson/diorama
128
+ licenses: []
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.6
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Store Rails view templates in your database.
150
+ test_files: []