panoramic 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +14 -0
  3. data/Gemfile.lock +119 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +90 -0
  6. data/Rakefile +16 -0
  7. data/lib/panoramic.rb +2 -0
  8. data/lib/panoramic/orm/active_record.rb +31 -0
  9. data/lib/panoramic/resolver.rb +64 -0
  10. data/panoramic.gemspec +18 -0
  11. data/spec/controllers/rendering_spec.rb +29 -0
  12. data/spec/dummy/Rakefile +7 -0
  13. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  14. data/spec/dummy/app/controllers/foo_controller.rb +12 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/models/database_template.rb +4 -0
  17. data/spec/dummy/app/views/layouts/application.html.erb +12 -0
  18. data/spec/dummy/config.ru +4 -0
  19. data/spec/dummy/config/application.rb +45 -0
  20. data/spec/dummy/config/boot.rb +10 -0
  21. data/spec/dummy/config/database.yml +22 -0
  22. data/spec/dummy/config/environment.rb +5 -0
  23. data/spec/dummy/config/environments/development.rb +26 -0
  24. data/spec/dummy/config/environments/production.rb +49 -0
  25. data/spec/dummy/config/environments/test.rb +35 -0
  26. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/spec/dummy/config/initializers/inflections.rb +10 -0
  28. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  29. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  30. data/spec/dummy/config/initializers/session_store.rb +8 -0
  31. data/spec/dummy/config/locales/en.yml +5 -0
  32. data/spec/dummy/config/routes.rb +4 -0
  33. data/spec/dummy/db/migrate/20110526132353_create_database_templates.rb +18 -0
  34. data/spec/dummy/db/schema.rb +26 -0
  35. data/spec/dummy/public/favicon.ico +0 -0
  36. data/spec/dummy/script/rails +6 -0
  37. data/spec/orm/active_record_spec.rb +79 -0
  38. data/spec/resolver_spec.rb +52 -0
  39. data/spec/spec_helper.rb +40 -0
  40. data/spec/support/describe_private.rb +14 -0
  41. data/spec/support/factories.rb +8 -0
  42. metadata +110 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ .rspec
8
+ coverage/*
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.7"
4
+
5
+ group :test do
6
+ gem "capybara", ">= 0.4.0"
7
+ gem 'factory_girl'
8
+ gem 'simplecov'
9
+ end
10
+
11
+ group :development, :test do
12
+ gem "sqlite3"
13
+ gem 'rspec-rails', '~> 2.6.0'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,119 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.7)
6
+ actionpack (= 3.0.7)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.7)
9
+ activemodel (= 3.0.7)
10
+ activesupport (= 3.0.7)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.7)
19
+ activesupport (= 3.0.7)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.7)
23
+ activemodel (= 3.0.7)
24
+ activesupport (= 3.0.7)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.7)
28
+ activemodel (= 3.0.7)
29
+ activesupport (= 3.0.7)
30
+ activesupport (3.0.7)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ capybara (0.4.1.2)
34
+ celerity (>= 0.7.9)
35
+ culerity (>= 0.2.4)
36
+ mime-types (>= 1.16)
37
+ nokogiri (>= 1.3.3)
38
+ rack (>= 1.0.0)
39
+ rack-test (>= 0.5.4)
40
+ selenium-webdriver (>= 0.0.27)
41
+ xpath (~> 0.1.3)
42
+ celerity (0.8.9)
43
+ childprocess (0.1.9)
44
+ ffi (~> 1.0.6)
45
+ culerity (0.2.15)
46
+ diff-lcs (1.1.2)
47
+ erubis (2.6.6)
48
+ abstract (>= 1.0.0)
49
+ factory_girl (1.3.3)
50
+ ffi (1.0.9)
51
+ i18n (0.5.0)
52
+ json_pure (1.5.1)
53
+ mail (2.2.19)
54
+ activesupport (>= 2.3.6)
55
+ i18n (>= 0.4.0)
56
+ mime-types (~> 1.16)
57
+ treetop (~> 1.4.8)
58
+ mime-types (1.16)
59
+ nokogiri (1.4.4)
60
+ polyglot (0.3.1)
61
+ rack (1.2.3)
62
+ rack-mount (0.6.14)
63
+ rack (>= 1.0.0)
64
+ rack-test (0.5.7)
65
+ rack (>= 1.0)
66
+ rails (3.0.7)
67
+ actionmailer (= 3.0.7)
68
+ actionpack (= 3.0.7)
69
+ activerecord (= 3.0.7)
70
+ activeresource (= 3.0.7)
71
+ activesupport (= 3.0.7)
72
+ bundler (~> 1.0)
73
+ railties (= 3.0.7)
74
+ railties (3.0.7)
75
+ actionpack (= 3.0.7)
76
+ activesupport (= 3.0.7)
77
+ rake (>= 0.8.7)
78
+ thor (~> 0.14.4)
79
+ rake (0.9.1)
80
+ rspec (2.6.0)
81
+ rspec-core (~> 2.6.0)
82
+ rspec-expectations (~> 2.6.0)
83
+ rspec-mocks (~> 2.6.0)
84
+ rspec-core (2.6.3)
85
+ rspec-expectations (2.6.0)
86
+ diff-lcs (~> 1.1.2)
87
+ rspec-mocks (2.6.0)
88
+ rspec-rails (2.6.1)
89
+ actionpack (~> 3.0)
90
+ activesupport (~> 3.0)
91
+ railties (~> 3.0)
92
+ rspec (~> 2.6.0)
93
+ rubyzip (0.9.4)
94
+ selenium-webdriver (0.2.1)
95
+ childprocess (>= 0.1.7)
96
+ ffi (>= 1.0.7)
97
+ json_pure
98
+ rubyzip
99
+ simplecov (0.4.2)
100
+ simplecov-html (~> 0.4.4)
101
+ simplecov-html (0.4.5)
102
+ sqlite3 (1.3.3)
103
+ thor (0.14.6)
104
+ treetop (1.4.9)
105
+ polyglot (>= 0.3.1)
106
+ tzinfo (0.3.27)
107
+ xpath (0.1.4)
108
+ nokogiri (~> 1.3)
109
+
110
+ PLATFORMS
111
+ ruby
112
+
113
+ DEPENDENCIES
114
+ capybara (>= 0.4.0)
115
+ factory_girl
116
+ rails (= 3.0.7)
117
+ rspec-rails (~> 2.6.0)
118
+ simplecov
119
+ sqlite3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Andrea Pavoni - http://andreapavoni.com
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,90 @@
1
+ # Panoramic
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
+
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.
5
+
6
+ ## Installation
7
+ Add the following line to Gemfile:
8
+
9
+ ```
10
+ gem database_templates
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Mandatory fields
16
+ Your model should have the following fields:
17
+
18
+ * body (text): the source of template
19
+ * path (string): where to find template (ex: layouts/application,
20
+ you_controller/action, etc...)
21
+ * locale (string): it depends from avaiable locales in your app
22
+ * handler (string): as locale field, it depends from avaiable handlers
23
+ (erb, haml, etc...)
24
+ * partial (boolean): determines if it's a partial or not (false by
25
+ default)
26
+
27
+ they're what the rails' Resolver API needs to lookup templates.
28
+
29
+ ### Model
30
+ 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).
31
+
32
+ ```
33
+ class TemplateStorage < ActiveRecord::Base
34
+ store_templates
35
+ end
36
+ ```
37
+
38
+ ### Controller
39
+ To add Panoramic::Resolver in controller, depending on your needs, you may choose:
40
+
41
+ * [prepend_view_path]: search for templates *first* in your resolver, *then* on filesystem
42
+ * [append_view_path]: search for templates *first* on filesystem, *then* in your resolver
43
+
44
+ **NOTE**: the above methods are both class and instance methods.
45
+
46
+
47
+ ```
48
+ class SomeController < ApplicationController
49
+ prepend_view_path TemplateStorage.resolver
50
+
51
+ def index
52
+ # as you may already know, rails will serve 'some/index' template by default, but it doesn't care where it is stored.
53
+ end
54
+
55
+ def show
56
+ # explicit render
57
+ render :template => 'custom_template'
58
+ end
59
+
60
+ def custom_template
61
+ # use another model to fetch templates
62
+ prepend_view_path AnotherModel.resolver
63
+ end
64
+ end
65
+ ```
66
+
67
+ ## Documentation
68
+ Need more help? Check out ```spec/dummy/```, you'll find a *dummy* rails app I used to make tests ;-)
69
+
70
+ ## Testing
71
+ Enter Panoramic gem path, run ```bundle install``` to install development and test dependencies, then ```rake spec```.
72
+
73
+
74
+ ## Todo
75
+ ### Short term
76
+ * make orm specs DRY to reuse them with different orms
77
+ * add, at least, Mongoid and DataMapper bindings
78
+ ### Long term
79
+ * add generators
80
+
81
+ ## Contributing
82
+ Fork, make your changes, then send a pull request.
83
+
84
+ ## Credits
85
+ The main idea was *heavily inspired* from José Valim's awesome book [Crafting Rails Applications]. It helped me to better understand some Rails internals.
86
+
87
+ [ActionView::Resolver]: http://api.rubyonrails.org/classes/ActionView/Resolver.html
88
+ [append_view_path]: http://apidock.com/rails/AbstractController/ViewPaths/ClassMethods/append_view_path
89
+ [prepend_view_path]: http://apidock.com/rails/AbstractController/ViewPaths/ClassMethods/prepend_view_path
90
+ [Crafting Rails Applications]: http://pragprog.com/titles/jvrails/crafting-rails-applications
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ begin
4
+ require 'bundler'
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ require 'rspec/core'
11
+ require 'rspec/core/rake_task'
12
+
13
+ Bundler::GemHelper.install_tasks
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ task :default => :spec
data/lib/panoramic.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'panoramic/resolver'
2
+ require 'panoramic/orm/active_record'
@@ -0,0 +1,31 @@
1
+ module Panoramic
2
+ module Orm
3
+ module ActiveRecord
4
+ def store_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)
10
+ validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)
11
+
12
+ after_save { Panoramic::Resolver.instance.clear_cache }
13
+
14
+ extend ClassMethods
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def find_model_templates(conditions = {})
20
+ self.where(conditions)
21
+ end
22
+
23
+ def resolver
24
+ Panoramic::Resolver.using self
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ ActiveRecord::Base.extend Panoramic::Orm::ActiveRecord
@@ -0,0 +1,64 @@
1
+ module Panoramic
2
+ class Resolver < ActionView::Resolver
3
+ require "singleton"
4
+ include Singleton
5
+
6
+ # this method is mandatory to implement a Resolver
7
+ def find_templates(name, prefix, partial, details)
8
+ conditions = {
9
+ :path => build_path(name, prefix),
10
+ :locale => normalize_array(details[:locale]).first,
11
+ :format => normalize_array(details[:formats]).first,
12
+ :handler => normalize_array(details[:handlers]),
13
+ :partial => partial || false
14
+ }
15
+
16
+ @@model.find_model_templates(conditions).map do |record|
17
+ initialize_template(record)
18
+ end
19
+ end
20
+
21
+ # Instantiate Resolver by passing a model (decoupled from ORMs)
22
+ def self.using(model)
23
+ @@model = model
24
+ self.instance
25
+ end
26
+
27
+ private
28
+
29
+ # Initialize an ActionView::Template object based on the record found.
30
+ def initialize_template(record)
31
+ source = record.body
32
+ identifier = "#{record.class} - #{record.id} - #{record.path.inspect}"
33
+ handler = ActionView::Template.registered_template_handler(record.handler)
34
+
35
+ details = {
36
+ :format => Mime[record.format],
37
+ :updated_at => record.updated_at,
38
+ :virtual_path => virtual_path(record.path, record.partial)
39
+ }
40
+
41
+ ActionView::Template.new(source, identifier, handler, details)
42
+ end
43
+
44
+ # Build path with eventual prefix
45
+ def build_path(name, prefix)
46
+ prefix.present? ? "#{prefix}/#{name}" : name
47
+ end
48
+
49
+ # Normalize array by converting all symbols to strings.
50
+ def normalize_array(array)
51
+ array.map(&:to_s)
52
+ end
53
+
54
+ # returns a path depending if its a partial or template
55
+ def virtual_path(path, partial)
56
+ return path unless partial
57
+ if index = path.rindex("/")
58
+ path.insert(index + 1, "_")
59
+ else
60
+ "_#{path}"
61
+ end
62
+ end
63
+ end
64
+ end
data/panoramic.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "panoramic"
5
+ s.version ='0.0.2'
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Andrea Pavoni"]
8
+ s.email = ["andrea.pavoni@gmail.com"]
9
+ s.homepage = "http://github.com/apeacox/panoramic"
10
+ s.summary = %q{Stores rails views on database}
11
+ s.description = %q{Stores rails views on database}
12
+
13
+ s.add_dependency 'rails', "~> 3.0.7"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe FooController do
4
+ include Capybara
5
+ render_views
6
+
7
+ context "renders views fetched from database with" do
8
+ it "a basic template" do
9
+ Factory.create(:database_template, :path => 'foo/default_layout')
10
+
11
+ visit '/foo/default_layout'
12
+
13
+ response.should render_template("foo/default_layout" )
14
+ page.body.should match(/something here in the body of the page: 4/)
15
+ end
16
+
17
+ it "a custom layout" do
18
+ Factory.create(:database_template, :path => 'foo/custom_layout')
19
+ Factory.create(:database_template, :path => 'layouts/custom', :body => 'This is a layout with body: <%= yield %>')
20
+
21
+ visit '/foo/custom_layout'
22
+
23
+ response.should render_template("layouts/custom" )
24
+ response.should render_template("foo/custom_layout" )
25
+ page.body.should match(/This is a layout with body:/)
26
+ page.body.should match(/something here in the body of the page:/)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,12 @@
1
+ class FooController < ApplicationController
2
+ prepend_view_path DatabaseTemplate.resolver
3
+
4
+ layout 'custom', :only => :custom_layout
5
+
6
+ def default_layout
7
+ end
8
+
9
+ def custom_layout
10
+ end
11
+ end
12
+
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class DatabaseTemplate < ActiveRecord::Base
2
+ # include DatabaseTemplates::Orm::ActiveRecord
3
+ store_templates
4
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tag %>
6
+ </head>
7
+ <body>
8
+
9
+ <%= yield %>
10
+
11
+ </body>
12
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "panoramic"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,26 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,35 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'd3115f72ad5880f2d9996fccbc8fea7778866b94b3653b9e712cf1ae8a21a7d6d3c1e6df116198db542f1be3a9112c9ebc15e43f8eb5138ac7e8a763a25a191c'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,4 @@
1
+ Dummy::Application.routes.draw do
2
+ get '/foo/default_layout' => 'foo#default_layout'
3
+ get '/foo/custom_layout' => 'foo#custom_layout'
4
+ end
@@ -0,0 +1,18 @@
1
+ class CreateDatabaseTemplates < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :database_templates do |t|
4
+ t.text :body
5
+ t.boolean :partial, :default => false
6
+ t.string :path
7
+ t.string :format
8
+ t.string :locale
9
+ t.string :handler
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :database_templates
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20110526132353) do
14
+
15
+ create_table "database_templates", :force => true do |t|
16
+ t.text "body"
17
+ t.boolean "partial", :default => false
18
+ t.string "path"
19
+ t.string "format"
20
+ t.string "locale"
21
+ t.string "handler"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Panoramic::Orm::ActiveRecord do
4
+ context "validations" do
5
+ let(:template) { Factory.build :database_template }
6
+
7
+ it "has body present" do
8
+ template.body = nil
9
+ template.should have(1).errors_on(:body)
10
+ end
11
+
12
+ context "MIME format" do
13
+ it "is valid" do
14
+ template.format = 'notknown'
15
+ template.should have(1).errors_on(:format)
16
+ end
17
+
18
+ it "is present" do
19
+ template.format = nil
20
+ template.should have(1).errors_on(:format)
21
+ end
22
+ end
23
+
24
+ context "locale" do
25
+ it "is valid" do
26
+ template.locale = 'notknown'
27
+ template.should have(1).errors_on(:locale)
28
+ end
29
+
30
+ it "is present" do
31
+ template.locale = nil
32
+ template.should have(1).errors_on(:locale)
33
+ end
34
+ end
35
+
36
+ context "handler" do
37
+ it "is valid" do
38
+ template.handler = 'notknown'
39
+ template.should have(1).errors_on(:handler)
40
+ end
41
+
42
+ it "is present" do
43
+ template.handler = nil
44
+ template.should have(1).errors_on(:handler)
45
+ end
46
+ end
47
+ end
48
+
49
+ context "cache" do
50
+ it "is expired on update" do
51
+ resolver = DatabaseTemplate.resolver
52
+
53
+ cache_key = Object.new
54
+ db_template = Factory.create(:database_template, :path => 'foo/some_list', :body => 'Listing something')
55
+
56
+ details = { :formats => [:html], :locale => [:en], :handlers => [:erb] }
57
+
58
+ template = resolver.find_all("some_list", "foo", false, details, cache_key).first
59
+ template.source.should match(/Listing something/)
60
+
61
+ db_template.update_attributes(:body => "New body for template")
62
+
63
+ template = resolver.find_all("some_list", "foo", false, details, cache_key).first
64
+ template.source.should match(/New body for template/)
65
+ end
66
+ end
67
+
68
+ context "#resolver" do
69
+ it "#returns a Resolver instance" do
70
+ DatabaseTemplate.resolver.should be_a(Panoramic::Resolver)
71
+ end
72
+ end
73
+
74
+ context "ActiveRecord::Base" do
75
+ it "responds to store_templates" do
76
+ ActiveRecord::Base.should respond_to(:store_templates)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Panoramic::Resolver do
4
+ let(:resolver) { Panoramic::Resolver.using(DatabaseTemplate) }
5
+
6
+ context ".find_templates" do
7
+ it "lookups templates for given params" do
8
+ template = Factory.create(:database_template, :path => 'foo/example')
9
+ details = { :formats => [:html], :locale => [:en], :handlers => [:erb] }
10
+ resolver.find_templates('example', 'foo', false, details).first.should_not be_nil
11
+ end
12
+ end
13
+ end
14
+
15
+ describe_private Panoramic::Resolver, '(private methods)' do
16
+ let(:resolver) { Panoramic::Resolver.using(DatabaseTemplate) }
17
+
18
+ context "#build_path" do
19
+ it "returns prefix/name if prefix is passed" do
20
+ resolver.build_path('path', 'prefix').should == 'prefix/path'
21
+ end
22
+
23
+ it "returns name if prefix is nil" do
24
+ resolver.build_path('path',nil).should == 'path'
25
+ end
26
+ end
27
+
28
+ context "#normalize_array" do
29
+ it "converts all symbols to strings" do
30
+ resolver.normalize_array([:something, 'that', :matters]).should == ['something','that','matters']
31
+ end
32
+ end
33
+
34
+ context "#initialize_template" do
35
+ let(:template) { Factory :database_template }
36
+
37
+ it "initializes an ActionView::Template object" do
38
+ resolver.initialize_template(template).should be_a(ActionView::Template)
39
+ end
40
+ end
41
+
42
+ context "#virtual_path" do
43
+ it "returns 'path' if is not a partial" do
44
+ resolver.virtual_path('path',false).should == 'path'
45
+ end
46
+
47
+ it "returns '_path' if is a partial" do
48
+ resolver.virtual_path('path',true).should == '_path'
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,40 @@
1
+ unless ENV['COVERAGE'].nil?
2
+ require 'simplecov'
3
+ SimpleCov.start 'rails' do
4
+ coverage_dir 'coverage'
5
+ end
6
+ end
7
+
8
+ ENV["RAILS_ENV"] = "test"
9
+
10
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
11
+ require "rails/test_help"
12
+ require "rspec/rails"
13
+ require 'factory_girl'
14
+
15
+ ActionMailer::Base.delivery_method = :test
16
+ ActionMailer::Base.perform_deliveries = true
17
+ ActionMailer::Base.default_url_options[:host] = "test.com"
18
+
19
+ Rails.backtrace_cleaner.remove_silencers!
20
+
21
+ # Configure capybara for integration testing
22
+ require "capybara/rails"
23
+ Capybara.default_driver = :rack_test
24
+ Capybara.default_selector = :css
25
+
26
+ # Run any available migration
27
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
28
+
29
+ # Load support files
30
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
31
+
32
+ RSpec.configure do |config|
33
+ # Remove this line if you don't want RSpec's should and should_not
34
+ # methods or matchers
35
+ require 'rspec/expectations'
36
+ config.include RSpec::Matchers
37
+
38
+ # == Mock Framework
39
+ config.mock_with :rspec
40
+ end
@@ -0,0 +1,14 @@
1
+ # taken from: http://kailuowang.blogspot.com/2010/08/testing-private-methods-in-rspec.html
2
+ def describe_private *args, &block
3
+ example = describe *args, &block
4
+ klass = args[0]
5
+ if klass.is_a? Class
6
+ saved_private_instance_methods = klass.private_instance_methods
7
+ example.before do
8
+ klass.class_eval { public *saved_private_instance_methods }
9
+ end
10
+ example.after do
11
+ klass.class_eval { private *saved_private_instance_methods }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ Factory.define :database_template do |t|
2
+ t.path 'foo/index'
3
+ t.format 'html'
4
+ t.locale 'en'
5
+ t.handler 'erb'
6
+ t.partial 'false'
7
+ t.body "something here in the body of the page: <%= 2 + 2 %>"
8
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panoramic
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Andrea Pavoni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-08 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.7
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ description: Stores rails views on database
28
+ email:
29
+ - andrea.pavoni@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - MIT-LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/panoramic.rb
44
+ - lib/panoramic/orm/active_record.rb
45
+ - lib/panoramic/resolver.rb
46
+ - panoramic.gemspec
47
+ - spec/controllers/rendering_spec.rb
48
+ - spec/dummy/Rakefile
49
+ - spec/dummy/app/controllers/application_controller.rb
50
+ - spec/dummy/app/controllers/foo_controller.rb
51
+ - spec/dummy/app/helpers/application_helper.rb
52
+ - spec/dummy/app/models/database_template.rb
53
+ - spec/dummy/app/views/layouts/application.html.erb
54
+ - spec/dummy/config.ru
55
+ - spec/dummy/config/application.rb
56
+ - spec/dummy/config/boot.rb
57
+ - spec/dummy/config/database.yml
58
+ - spec/dummy/config/environment.rb
59
+ - spec/dummy/config/environments/development.rb
60
+ - spec/dummy/config/environments/production.rb
61
+ - spec/dummy/config/environments/test.rb
62
+ - spec/dummy/config/initializers/backtrace_silencers.rb
63
+ - spec/dummy/config/initializers/inflections.rb
64
+ - spec/dummy/config/initializers/mime_types.rb
65
+ - spec/dummy/config/initializers/secret_token.rb
66
+ - spec/dummy/config/initializers/session_store.rb
67
+ - spec/dummy/config/locales/en.yml
68
+ - spec/dummy/config/routes.rb
69
+ - spec/dummy/db/migrate/20110526132353_create_database_templates.rb
70
+ - spec/dummy/db/schema.rb
71
+ - spec/dummy/public/favicon.ico
72
+ - spec/dummy/script/rails
73
+ - spec/orm/active_record_spec.rb
74
+ - spec/resolver_spec.rb
75
+ - spec/spec_helper.rb
76
+ - spec/support/describe_private.rb
77
+ - spec/support/factories.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/apeacox/panoramic
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 1525969138738555254
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.6.2
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Stores rails views on database
109
+ test_files: []
110
+