Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Release 1.0

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

0 notes on commit eddd5e5

Please sign in to comment.
Something went wrong with that request. Please try again.