Permalink
Browse files

Release 1.0

  • Loading branch information...
1 parent baf538b commit eddd5e5baa0193cd6e30a4df267e6e37acb5c0d2 @loicvigneron loicvigneron committed Mar 7, 2012
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
179 LICENSE
@@ -0,0 +1,179 @@
+Copyright (C) 2011 Thibault Poncelet <thibault.poncelet@student.uclouvain.be>
+Copyright (C) 2011 Loic Vigneron <loic.vigneron@student.uclouvain.be>
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
+========================
+
+Master thesis : The phenomenal gem
+Prof : Kim Mens
+Year : 2011-2012
+Students names,sections :
+ - Poncelet Thibault (SINF22MS)
+ - Vigneron Loic (SINF22MS)
+Start date : May 1, 2011
+
View
0 app/assets/images/phenomenal_rails/.gitkeep
No changes.
View
9 app/assets/javascripts/phenomenal_rails/application.js
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
7 app/assets/stylesheets/phenomenal_rails/application.css
@@ -0,0 +1,7 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
View
4 app/controllers/phenomenal_rails/application_controller.rb
@@ -0,0 +1,4 @@
+module PhenomenalRails
+ class ApplicationController < ActionController::Base
+ end
+end
View
14 app/views/layouts/phenomenal_rails/application.html.erb
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>PhenomenalRails</title>
+ <%= stylesheet_link_tag "phenomenal-rails/application" %>
+ <%= javascript_include_tag "phenomenal-rails/application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
View
43 lib/phenomenal_rails.rb
@@ -0,0 +1,43 @@
+require "phenomenal"
+require "phenomenal_rails/context"
+require "phenomenal_rails/middleware"
+require "phenomenal_rails/engine"
+require "singleton"
+require "phenomenal_rails/resolver"
+
+# Set default context as persistent
+phen_default_context.persistent=true
+
+module PhenomenalRails
+ def self.load_dir(path)
+ if Dir.exist? path
+ Dir.entries(path).each do |entry|
+ if entry!="." && entry !=".."
+ filepath=File.join(path,entry)
+ if File.file?(filepath) && entry.match(/.*\.rb/)
+ load filepath
+ elsif File.directory?(filepath)
+ load_dir(filepath)
+ end
+ end
+ end
+ end
+ end
+
+ ActionDispatch::Callbacks.before do
+ phen_defined_contexts.reverse.each do |context|
+ if !context.forgotten && (!context.persistent || !Rails.configuration.cache_classes)
+ while phen_context_active?(context) do
+ phen_deactivate_context(context)
+ end
+ # Fix problem without page caching
+ if !Rails.configuration.cache_classes
+ phen_forget_context(context)
+ end
+ end
+ end
+ if !Rails.configuration.cache_classes
+ PhenomenalRails.load_dir("#{Rails.root}/app/contexts")
+ end
+ end
+end
View
22 lib/phenomenal_rails/context.rb
@@ -0,0 +1,22 @@
+# Add persistent attribute to the context class, allowing to disable
+# auto deactivation between HTTP requests
+class Phenomenal::Context
+ attr_accessor :persistent
+ #DSL inside context definition
+ def is_persistent
+ @persistent = true
+ activate
+ end
+
+ def to_path
+ if name
+ name.to_s.underscore
+ elsif self==manager.default_context
+ nil
+ elsif manager.combined_contexts[self]
+ manager.combined_contexts[self].flatten.join("/").underscore
+ else
+ nil
+ end
+ end
+end
View
12 lib/phenomenal_rails/engine.rb
@@ -0,0 +1,12 @@
+module PhenomenalRails
+ class Engine < Rails::Engine
+ isolate_namespace PhenomenalRails
+ config.app_middleware.use(PhenomenalRails::Middleware)
+ config.after_initialize do
+ ActionController::Base.view_paths.paths.insert(0,Phenomenal::Resolver.instance)
+ end
+ end
+end
+
+
+
View
15 lib/phenomenal_rails/middleware.rb
@@ -0,0 +1,15 @@
+module PhenomenalRails
+ class Middleware
+ def initialize(app)
+ @app=app
+ end
+
+ def call(env)
+ PhenomenalRails::Middleware.activation_handler(env)
+ @app.call(env)
+ end
+
+ def self.activation_handler(env)
+ end
+ end
+end
View
58 lib/phenomenal_rails/resolver.rb
@@ -0,0 +1,58 @@
+class Phenomenal::Resolver < ActionView::FileSystemResolver
+ include Singleton
+
+ def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
+ contexts = find_sorted_active_contexts
+ contexts.each do |context|
+ context_path = context.to_path
+ if !context_path.nil?
+ path = Path.build(name, "#{context_path}/views/#{prefix}", partial)
+ query = query(path, details, details[:formats])
+ locals = locals.map { |x| x.to_s }.sort!
+ decorate(query,[name,prefix,partial],details,locals)
+ return query unless query.empty?
+ end
+ end
+ return []
+ end
+
+ def query(path, details, formats)
+ query = build_query(path, details)
+ # deals with case-insensitive file systems.
+ sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] }
+ template_paths = Dir[query].reject { |filename|
+ File.directory?(filename) ||
+ !sanitizer[File.dirname(filename)].include?(filename)
+ }
+ template_paths.map { |template|
+ cached(template, path, formats) do
+ handler, format = extract_handler_and_format(template, formats)
+ contents = File.binread template
+
+ ActionView::Template.new(contents, File.expand_path(template), handler,
+ :virtual_path => path.virtual,
+ :format => format,
+ :updated_at => mtime(template))
+ end
+ }
+ end
+
+ private
+ def initialize()
+ super("app/contexts")
+ @cached={}
+ end
+
+ def cached(template, path, formats)
+ if caching?
+ @cached[template]||=yield
+ else
+ yield
+ end
+ end
+
+ def find_sorted_active_contexts
+ contexts = phen_defined_contexts.find_all{|c| c.active?}
+ contexts.sort!{|a,b| Phenomenal::Manager.instance.conflict_policy(a,b)}
+ end
+end
View
3 lib/phenomenal_rails/version.rb
@@ -0,0 +1,3 @@
+module PhenomenalRails
+ VERSION = "1.0.0"
+end
View
4 lib/tasks/phenomenal_rails_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :phenomenal-rails do
+# # Task goes here
+# end
View
23 phenomenal_rails.gemspec
@@ -0,0 +1,23 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "phenomenal_rails/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "phenomenal_rails"
+ s.version = PhenomenalRails::VERSION
+ s.authors = "Loic Vigneron - Thibault Poncelet"
+ s.email = "thibault.poncelet@student.uclouvain.be - loic.vigneron@student.uclouvain.be"
+ s.homepage = "http://www.phenomenal-gem.com"
+ s.summary = "Rails glue for phenomenal"
+ s.description = "Rails integration of phenomenal"
+
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["spec/**/*"]
+
+ s.add_dependency "rails", ">= 3.1.0"
+ s.add_dependency "phenomenal", ">= 1.0.1"
+
+ s.add_development_dependency "rspec-rails", "~> 2.5"
+end
View
32 spec/spec_helper.rb
@@ -0,0 +1,32 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] = 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end

0 comments on commit eddd5e5

Please sign in to comment.