panoramic 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +3 -4
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +124 -111
  6. data/README.md +26 -9
  7. data/Rakefile +18 -1
  8. data/gemfiles/active_record.gemfile +5 -0
  9. data/lib/panoramic/orm/active_record.rb +3 -3
  10. data/lib/panoramic/resolver.rb +8 -5
  11. data/panoramic.gemspec +3 -3
  12. data/spec/controllers/rendering_spec.rb +7 -7
  13. data/spec/dummy/Rakefile +1 -2
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -1
  15. data/spec/dummy/app/models/.keep +0 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +3 -1
  17. data/spec/dummy/bin/bundle +3 -0
  18. data/spec/dummy/bin/rails +4 -0
  19. data/spec/dummy/bin/rake +4 -0
  20. data/spec/dummy/bin/setup +29 -0
  21. data/spec/dummy/config.ru +2 -2
  22. data/spec/dummy/config/application.rb +7 -21
  23. data/spec/dummy/config/boot.rb +4 -9
  24. data/spec/dummy/config/database.yml +11 -8
  25. data/spec/dummy/config/environment.rb +3 -3
  26. data/spec/dummy/config/environments/development.rb +28 -13
  27. data/spec/dummy/config/environments/production.rb +58 -28
  28. data/spec/dummy/config/environments/test.rb +22 -15
  29. data/spec/dummy/config/initializers/assets.rb +11 -0
  30. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  31. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  32. data/spec/dummy/config/initializers/inflections.rb +9 -3
  33. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  34. data/spec/dummy/config/initializers/session_store.rb +1 -6
  35. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  36. data/spec/dummy/config/locales/en.yml +20 -2
  37. data/spec/dummy/config/routes.rb +1 -1
  38. data/spec/dummy/config/secrets.yml +22 -0
  39. data/spec/orm/active_record_spec.rb +26 -26
  40. data/spec/resolver_spec.rb +36 -8
  41. metadata +77 -46
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3484de7a6c858f54f6201c48ea1316778c287e8
4
+ data.tar.gz: 348040f2ae3bec77b8b15972881554e22dfd1373
5
+ SHA512:
6
+ metadata.gz: a33a457703b4537f021e126eb7013b08999f6da892d34153c75397627230cf8a3a5a9bda182437d49ab8234d5c42c5985544ca48c77a5793fa0cd6879f2a7623
7
+ data.tar.gz: b8de6b181357e5db23eaf7121bd849dbc7a0c3279d780fa5ff1b0c17d6347d13171d10a056a5154f66bef22d7d0e4e254c880b5c697ad7b5f4add18337f192e9
data/.gitignore CHANGED
@@ -7,3 +7,5 @@ spec/dummy/tmp/
7
7
  .rspec
8
8
  coverage/*
9
9
  .rvmrc
10
+ gemfiles/*.lock
11
+ *.rdb
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 1.9.2
5
- - 1.8.7
6
- - ree
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.2.0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  group :test do
data/Gemfile.lock CHANGED
@@ -1,137 +1,150 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- panoramic (0.0.4)
4
+ panoramic (0.0.6)
5
5
  rails (>= 3.0.7)
6
6
 
7
7
  GEM
8
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
- actionmailer (3.2.6)
11
- actionpack (= 3.2.6)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.6)
14
- activemodel (= 3.2.6)
15
- activesupport (= 3.2.6)
16
- builder (~> 3.0.0)
10
+ actionmailer (4.2.5.1)
11
+ actionpack (= 4.2.5.1)
12
+ actionview (= 4.2.5.1)
13
+ activejob (= 4.2.5.1)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.5.1)
17
+ actionview (= 4.2.5.1)
18
+ activesupport (= 4.2.5.1)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.5.1)
24
+ activesupport (= 4.2.5.1)
25
+ builder (~> 3.1)
17
26
  erubis (~> 2.7.0)
18
- journey (~> 1.0.1)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.1.3)
23
- activemodel (3.2.6)
24
- activesupport (= 3.2.6)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.6)
27
- activemodel (= 3.2.6)
28
- activesupport (= 3.2.6)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.6)
32
- activemodel (= 3.2.6)
33
- activesupport (= 3.2.6)
34
- activesupport (3.2.6)
35
- i18n (~> 0.6)
36
- multi_json (~> 1.0)
37
- arel (3.0.2)
38
- builder (3.0.0)
39
- capybara (1.1.2)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.5.1)
30
+ activesupport (= 4.2.5.1)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.5.1)
33
+ activesupport (= 4.2.5.1)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.5.1)
36
+ activemodel (= 4.2.5.1)
37
+ activesupport (= 4.2.5.1)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.5.1)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ arel (6.0.3)
46
+ builder (3.2.2)
47
+ capybara (2.5.0)
40
48
  mime-types (>= 1.16)
41
49
  nokogiri (>= 1.3.3)
42
50
  rack (>= 1.0.0)
43
51
  rack-test (>= 0.5.4)
44
- selenium-webdriver (~> 2.0)
45
- xpath (~> 0.1.4)
46
- childprocess (0.3.0)
47
- ffi (~> 1.0.6)
48
- diff-lcs (1.1.3)
52
+ xpath (~> 2.0)
53
+ concurrent-ruby (1.0.0)
54
+ diff-lcs (1.2.5)
55
+ docile (1.1.5)
49
56
  erubis (2.7.0)
50
- factory_girl (2.5.0)
51
- activesupport
52
- ffi (1.0.11)
53
- hike (1.2.1)
54
- i18n (0.6.0)
55
- journey (1.0.4)
56
- json (1.7.3)
57
- mail (2.4.4)
58
- i18n (>= 0.4.0)
59
- mime-types (~> 1.16)
60
- treetop (~> 1.4.8)
61
- mime-types (1.19)
62
- multi_json (1.0.4)
63
- nokogiri (1.5.0)
64
- polyglot (0.3.3)
65
- rack (1.4.1)
66
- rack-cache (1.2)
67
- rack (>= 0.4)
68
- rack-ssl (1.3.2)
69
- rack
70
- rack-test (0.6.1)
57
+ factory_girl (4.5.0)
58
+ activesupport (>= 3.0.0)
59
+ globalid (0.3.6)
60
+ activesupport (>= 4.1.0)
61
+ i18n (0.7.0)
62
+ json (1.8.3)
63
+ loofah (2.0.3)
64
+ nokogiri (>= 1.5.9)
65
+ mail (2.6.3)
66
+ mime-types (>= 1.16, < 3)
67
+ mime-types (2.99.1)
68
+ mini_portile2 (2.0.0)
69
+ minitest (5.8.4)
70
+ nokogiri (1.6.7.2)
71
+ mini_portile2 (~> 2.0.0.rc2)
72
+ rack (1.6.4)
73
+ rack-test (0.6.3)
71
74
  rack (>= 1.0)
72
- rails (3.2.6)
73
- actionmailer (= 3.2.6)
74
- actionpack (= 3.2.6)
75
- activerecord (= 3.2.6)
76
- activeresource (= 3.2.6)
77
- activesupport (= 3.2.6)
78
- bundler (~> 1.0)
79
- railties (= 3.2.6)
80
- railties (3.2.6)
81
- actionpack (= 3.2.6)
82
- activesupport (= 3.2.6)
83
- rack-ssl (~> 1.3.2)
75
+ rails (4.2.5.1)
76
+ actionmailer (= 4.2.5.1)
77
+ actionpack (= 4.2.5.1)
78
+ actionview (= 4.2.5.1)
79
+ activejob (= 4.2.5.1)
80
+ activemodel (= 4.2.5.1)
81
+ activerecord (= 4.2.5.1)
82
+ activesupport (= 4.2.5.1)
83
+ bundler (>= 1.3.0, < 2.0)
84
+ railties (= 4.2.5.1)
85
+ sprockets-rails
86
+ rails-deprecated_sanitizer (1.0.3)
87
+ activesupport (>= 4.2.0.alpha)
88
+ rails-dom-testing (1.0.7)
89
+ activesupport (>= 4.2.0.beta, < 5.0)
90
+ nokogiri (~> 1.6.0)
91
+ rails-deprecated_sanitizer (>= 1.0.1)
92
+ rails-html-sanitizer (1.0.3)
93
+ loofah (~> 2.0)
94
+ railties (4.2.5.1)
95
+ actionpack (= 4.2.5.1)
96
+ activesupport (= 4.2.5.1)
84
97
  rake (>= 0.8.7)
85
- rdoc (~> 3.4)
86
- thor (>= 0.14.6, < 2.0)
87
- rake (0.9.2.2)
88
- rdoc (3.12)
89
- json (~> 1.4)
90
- rspec (2.10.0)
91
- rspec-core (~> 2.10.0)
92
- rspec-expectations (~> 2.10.0)
93
- rspec-mocks (~> 2.10.0)
94
- rspec-core (2.10.1)
95
- rspec-expectations (2.10.0)
96
- diff-lcs (~> 1.1.3)
97
- rspec-mocks (2.10.1)
98
- rspec-rails (2.10.1)
99
- actionpack (>= 3.0)
100
- activesupport (>= 3.0)
101
- railties (>= 3.0)
102
- rspec (~> 2.10.0)
103
- rubyzip (0.9.5)
104
- selenium-webdriver (2.18.0)
105
- childprocess (>= 0.2.5)
106
- ffi (~> 1.0.9)
107
- multi_json (~> 1.0.4)
108
- rubyzip
109
- simplecov (0.5.4)
110
- multi_json (~> 1.0.3)
111
- simplecov-html (~> 0.5.3)
112
- simplecov-html (0.5.3)
113
- sprockets (2.1.3)
114
- hike (~> 1.2)
115
- rack (~> 1.0)
116
- tilt (~> 1.1, != 1.3.0)
117
- sqlite3 (1.3.5)
118
- thor (0.15.4)
119
- tilt (1.3.3)
120
- treetop (1.4.10)
121
- polyglot
122
- polyglot (>= 0.3.1)
123
- tzinfo (0.3.33)
124
- xpath (0.1.4)
98
+ thor (>= 0.18.1, < 2.0)
99
+ rake (10.5.0)
100
+ rspec-core (3.4.3)
101
+ rspec-support (~> 3.4.0)
102
+ rspec-expectations (3.4.0)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.4.0)
105
+ rspec-mocks (3.4.1)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.4.0)
108
+ rspec-rails (3.4.2)
109
+ actionpack (>= 3.0, < 4.3)
110
+ activesupport (>= 3.0, < 4.3)
111
+ railties (>= 3.0, < 4.3)
112
+ rspec-core (~> 3.4.0)
113
+ rspec-expectations (~> 3.4.0)
114
+ rspec-mocks (~> 3.4.0)
115
+ rspec-support (~> 3.4.0)
116
+ rspec-support (3.4.1)
117
+ simplecov (0.11.2)
118
+ docile (~> 1.1.0)
119
+ json (~> 1.8)
120
+ simplecov-html (~> 0.10.0)
121
+ simplecov-html (0.10.0)
122
+ sprockets (3.5.2)
123
+ concurrent-ruby (~> 1.0)
124
+ rack (> 1, < 3)
125
+ sprockets-rails (3.0.2)
126
+ actionpack (>= 4.0)
127
+ activesupport (>= 4.0)
128
+ sprockets (>= 3.0.0)
129
+ sqlite3 (1.3.11)
130
+ thor (0.19.1)
131
+ thread_safe (0.3.5)
132
+ tzinfo (1.2.2)
133
+ thread_safe (~> 0.1)
134
+ xpath (2.0.0)
125
135
  nokogiri (~> 1.3)
126
136
 
127
137
  PLATFORMS
128
138
  ruby
129
139
 
130
140
  DEPENDENCIES
131
- capybara (~> 1.1.2)
141
+ capybara (~> 2.5.0)
132
142
  factory_girl
133
143
  panoramic!
134
144
  rake
135
- rspec-rails (~> 2.10.0)
145
+ rspec-rails (~> 3.0)
136
146
  simplecov
137
147
  sqlite3
148
+
149
+ BUNDLED WITH
150
+ 1.11.2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Panoramic
1
+ # Panoramic [![Build Status](https://secure.travis-ci.org/apeacox/panoramic.png)](http://travis-ci.org/apeacox/panoramic)
2
2
  An [ActionView::Resolver] implementation to store rails views (layouts, templates and partials) on database. Simply put: what you can do with views on filesystem, can be done on database.
3
3
 
4
4
  **NOTE:** at the moment, only ActiveRecord is supported, I've planned to add more ORMs (see Todo). If you can't wait, adding other ORMs should be very trivial.
@@ -6,8 +6,8 @@ An [ActionView::Resolver] implementation to store rails views (layouts, template
6
6
  ## Installation
7
7
  Add the following line to Gemfile:
8
8
 
9
- ```
10
- gem "panoramic", "~> 0.0.3"
9
+ ```ruby
10
+ gem "panoramic"
11
11
  ```
12
12
 
13
13
  ## Usage
@@ -18,7 +18,7 @@ Your model should have the following fields:
18
18
  * body (text): the source of template
19
19
  * path (string): where to find template (ex: layouts/application,
20
20
  you_controller/action, etc...)
21
- * locale (string): it depends from avaiable locales in your app
21
+ * locale (string): it depends from available locales in your app
22
22
  * handler (string): as locale field, it depends from avaiable handlers
23
23
  (erb, haml, etc...)
24
24
  * partial (boolean): determines if it's a partial or not (false by
@@ -30,7 +30,7 @@ they're what the rails' Resolver API needs to lookup templates.
30
30
  ### Model
31
31
  A simple macro in model will activate your new Resolver. You can use a dedicated model to manage all the views in your app, or just for specific needs (ex: you want a custom template for some static pages, the other views will be fetched from filesystem).
32
32
 
33
- ```
33
+ ```ruby
34
34
  class TemplateStorage < ActiveRecord::Base
35
35
  store_templates
36
36
  end
@@ -45,7 +45,7 @@ To add Panoramic::Resolver in controller, depending on your needs, you may choos
45
45
  **NOTE**: the above methods are both class and instance methods.
46
46
 
47
47
 
48
- ```
48
+ ```ruby
49
49
  class SomeController < ApplicationController
50
50
  prepend_view_path TemplateStorage.resolver
51
51
 
@@ -65,6 +65,25 @@ class SomeController < ApplicationController
65
65
  end
66
66
  ```
67
67
 
68
+ And let's say you want to use database template resolving in all your controllers, but
69
+ want to use panoramic only for certain paths (prefixed with X) you can use
70
+
71
+ ```ruby
72
+ class ApplicationController < ActionController::Base
73
+ prepend_view_path TemplateStorage.resolver(:only => 'use_this_prefix_only')
74
+ end
75
+ ```
76
+
77
+ This helps reducing the number of database requests, if Rails for example tries to look
78
+ for layouts per controller.
79
+
80
+ ### ActionMailer
81
+
82
+ ```ruby
83
+ class MyEmail < ActionMailer::Base
84
+ prepend_view_path TemplateStorage.resolver
85
+ ```
86
+
68
87
  ## Documentation
69
88
  Need more help? Check out ```spec/dummy/```, you'll find a *dummy* rails app I used to make tests ;-)
70
89
 
@@ -73,9 +92,7 @@ Enter Panoramic gem path, run ```bundle install``` to install development and te
73
92
 
74
93
 
75
94
  ## Todo
76
- ### Short term
77
- * make orm specs DRY to reuse them with different orms
78
- * add, at least, Mongoid and DataMapper bindings
95
+
79
96
  ### Long term
80
97
  * add generators
81
98
 
data/Rakefile CHANGED
@@ -13,4 +13,21 @@ require 'rspec/core/rake_task'
13
13
  Bundler::GemHelper.install_tasks
14
14
  RSpec::Core::RakeTask.new(:spec)
15
15
 
16
- task :default => :spec
16
+ ORMS = %w(active_record)
17
+
18
+ task :default => "spec:all"
19
+
20
+ namespace :spec do
21
+ ORMS.each do |orm|
22
+ desc "Run Tests against #{orm}"
23
+ task orm do
24
+ sh "BUNDLE_GEMFILE='gemfiles/#{orm}.gemfile' bundle --quiet"
25
+ sh "BUNDLE_GEMFILE='gemfiles/#{orm}.gemfile' bundle exec rake -t spec"
26
+ end
27
+ end
28
+
29
+ desc "Run Tests against all ORMs"
30
+ task :all do
31
+ ORMS.each { |orm| Rake::Task["spec:#{orm}"].invoke }
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'activerecord', '>= 3.2.8', :require => 'active_record'
4
+
5
+ gemspec :path => '../'
@@ -6,7 +6,7 @@ module Panoramic
6
6
  validates :body, :presence => true
7
7
  validates :path, :presence => true
8
8
  validates :format, :inclusion => Mime::SET.symbols.map(&:to_s)
9
- validates :locale, :inclusion => I18n.available_locales.map(&:to_s)
9
+ validates :locale, :inclusion => I18n.available_locales.map(&:to_s), :allow_blank => true
10
10
  validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)
11
11
 
12
12
  after_save { Panoramic::Resolver.instance.clear_cache }
@@ -20,8 +20,8 @@ module Panoramic
20
20
  self.where(conditions)
21
21
  end
22
22
 
23
- def resolver
24
- Panoramic::Resolver.using self
23
+ def resolver(options={})
24
+ Panoramic::Resolver.using self, options
25
25
  end
26
26
  end
27
27
  end
@@ -4,11 +4,13 @@ module Panoramic
4
4
  include Singleton
5
5
 
6
6
  # this method is mandatory to implement a Resolver
7
- def find_templates(name, prefix, partial, details)
7
+ def find_templates(name, prefix, partial, details, key=nil, locals=[])
8
+ return [] if @@resolver_options[:only] && !@@resolver_options[:only].include?(prefix)
9
+
8
10
  conditions = {
9
11
  :path => build_path(name, prefix),
10
- :locale => normalize_array(details[:locale]).first,
11
- :format => normalize_array(details[:formats]).first,
12
+ :locale => [normalize_array(details[:locale]).first, nil],
13
+ :format => normalize_array(details[:formats]),
12
14
  :handler => normalize_array(details[:handlers]),
13
15
  :partial => partial || false
14
16
  }
@@ -19,8 +21,9 @@ module Panoramic
19
21
  end
20
22
 
21
23
  # Instantiate Resolver by passing a model (decoupled from ORMs)
22
- def self.using(model)
24
+ def self.using(model, options={})
23
25
  @@model = model
26
+ @@resolver_options = options
24
27
  self.instance
25
28
  end
26
29
 
@@ -50,7 +53,7 @@ module Panoramic
50
53
  def normalize_array(array)
51
54
  array.map(&:to_s)
52
55
  end
53
-
56
+
54
57
  # returns a path depending if its a partial or template
55
58
  def virtual_path(path, partial)
56
59
  return path unless partial