Browse files

WIP: moving to gem adding actual jquery.cookie.js

  • Loading branch information...
1 parent 9a37175 commit 24d4c11ae62d76bb78564caa732054f4824baf66 @pboling pboling committed Sep 9, 2011
View
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
View
55 .gitignore
@@ -1,7 +1,48 @@
-*.iml
-*.ipr
-*.iws
-*.sw?
-.idea
-.DS_Store
-.svn
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+#.DS_Store
+
+# For TextMate
+#*.tmproj
+#tmtags
+
+# For emacs:
+#*~
+#\#*
+#.\#*
+
+# For vim:
+#*.swp
+
+# For redcar:
+#.redcar
+
+# For rubinius:
+#*.rbc
View
13 Gemfile
@@ -0,0 +1,13 @@
+source "http://rubygems.org"
+# Add dependencies required to use your gem here.
+# Example:
+# gem "activesupport", ">= 2.3.5"
+
+# Add dependencies to develop your gem here.
+# Include everything needed to run rake, tests, features, etc.
+group :development do
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.6.4"
+ gem "rcov", ">= 0"
+end
View
21 LICENSE.txt
@@ -0,0 +1,21 @@
+Copyright (c) 2007-2010 Pivotal Labs
+Copyright (c) 2011 Peter H. Boling (http://peterboling.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
33 README.rdoc
@@ -4,11 +4,20 @@ CacheableFlash
Note: This fork (http://github.com/pboling/cacheable-flash/tree/master) of
cacheable-flash aims to be a drop-in replacement for the original cacheable-flash
(by Pivotal) but uses JQuery instead of Prototype, and merged several of the forks
-of the project to collect the best features and improvements.
+of the project to collect the best features and improvements. It has also been made
+compatible with Rails 3, and turned into a gem.
+
+== Installation as plugin
-== Installation
ruby script/plugin install git://github.com/pboling/cacheable-flash.git
+== Installation as gem
+
+gem install 'cacheable_flash'
+
+add to your Gemfile:
+gem 'cacheable_flash'
+
== Description
This plugin enables greater levels of page caching by rendering flash
@@ -100,4 +109,22 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
end
end
-Copyright (c) 2007-2010 Pivotal Labs. This software is licensed under the MIT License.
+== Contributing to cacheable-flash
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+== Copyright
+
+Licensed under the MIT License.
+
+Copyright (c) 2011 Peter H. Boling (http://peterboling.com). See LICENSE.txt for further details.
+Copyright (c) 2007-2010 Pivotal Labs
+
+
+
View
96 Rakefile
@@ -1,63 +1,53 @@
+# encoding: utf-8
+
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'fileutils'
-include FileUtils
-
-PKG_VERSION = "0.1.5"
-desc 'Default: run specs.'
-task :default => :spec
-
-desc 'Test the cacheable_flash plugin.'
-Rake::TestTask.new(:spec) do |t|
- t.libs << 'lib'
- t.pattern = 'spec/**/*_spec.rb'
- t.verbose = true
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "cacheable-flash"
+ gem.homepage = "http://github.com/pboling/cacheable-flash"
+ gem.license = "MIT"
+ gem.summary = %Q{TODO: one-line summary of your gem}
+ gem.description = %Q{TODO: longer description of your gem}
+ gem.email = "peter.boling@peterboling.com"
+ gem.authors = ["pboling"]
+ # dependencies defined in Gemfile
end
+Jeweler::RubygemsDotOrgTasks.new
-desc 'Generate documentation for the cacheable_flash plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'CacheableFlash'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
end
-desc 'Tag the current release'
-task(:tag_release) {tag_release}
+require 'rcov/rcovtask'
+Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+ test.rcov_opts << '--exclude "gems/*"'
+end
-desc 'Package the release as a tarball'
-task(:pkg) {package_release}
+task :default => :test
-def tag_release
- user = ENV['USER'] || nil
- user_part = user ? "#{user}@" : ""
- svn_path = "svn+ssh://#{user_part}rubyforge.org/var/svn/pivotalrb/cacheable_flash"
- `svn cp #{svn_path}/trunk #{svn_path}/tags/REL-#{dashed_version} -m 'Version #{PKG_VERSION}'`
-end
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
-def package_release
- dir = File.dirname(__FILE__)
- mkdir_p "#{dir}/pkg"
- files = [
- "README.rdoc",
- "CHANGES",
- "init.rb",
- "install.rb",
- "uninstall.rb",
- "lib",
- "javascripts",
- "tasks",
- "spec",
- ]
- files = files.collect { |f| "cacheable_flash/#{f}" }
- Dir.chdir("#{dir}/..") do
- `tar zcvf cacheable_flash/pkg/cacheable_flash-#{dashed_version}.tgz #{files.join(' ')}`
- end
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "cacheable-flash #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
end
-
-def dashed_version
- PKG_VERSION.gsub('.', '-')
-end
View
3 init.rb
@@ -1,2 +1,3 @@
+require "json"
require "cacheable_flash"
-ActionView::Helpers::AssetTagHelper.register_javascript_include_default('jquery.cookie','flash')
+#ActionView::Helpers::AssetTagHelper.register_javascript_include_default('jquery.cookie','flash')
View
2 install.rb
@@ -1,3 +1,5 @@
+# Only executed when installed as plugin.
+# When installed as a gem must use the generator
require 'fileutils'
include FileUtils
View
33 javascripts/flash.js
@@ -1,33 +0,0 @@
-var Flash = new Object();
-
-Flash.data = {};
-
-Flash.json_parse = function (text)
-{
- try
- {
- return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, '')))
- && eval('(' + text + ')');
- } catch (e) {
- return false;
- }
-};
-
-Flash.transferFromCookies = function()
-{
- var json = $.cookie("flash").replace(/\+/g, " ").replace(/%2B/g, "+");
- var data = Flash.json_parse(json);
- if (!data) data = {};
- Flash.data = data;
- $.cookie("flash", null); // remove cookie
-};
-
-Flash.writeDataTo = function(name, element)
-{
- element = $(element);
- var content = "";
- if(Flash.data[name]) {
- content = Flash.data[name].toString();
- }
- element.html(unescape(content));
-};
View
1 javascripts/jquery.cookie.js
View
7 lib/cacheable_flash.rb
@@ -1,4 +1,11 @@
module CacheableFlash
+ if ::Rails.version < "3.1"
+ require 'jquery/rails/railtie'
+ else
+ require 'jquery/rails/engine'
+ end
+ require 'jquery/rails/version'
+
def self.included(base)
base.around_filter :write_flash_to_cookie
end
View
13 lib/cacheable_flash/engine.rb
@@ -0,0 +1,13 @@
+# Configure Rails 3.1:
+# This gem contains this empty engine class which inherits from Rails::Engine.
+# By doing this, Rails is informed that the directory for this gem may contain assets and the
+# app/assets, lib/assets and vendor/assets directories of this engine are added to the search path of Sprockets.
+module Jquery
+ module Rails
+
+ class Engine < ::Rails::Engine
+
+ end
+
+ end
+end
View
12 lib/cacheable_flash/railtie.rb
@@ -0,0 +1,12 @@
+# Configure Rails 3.0 to use public/javascripts/flash et al
+module Jquery
+ module Rails
+
+ class Railtie < ::Rails::Railtie
+ config.before_configuration do
+ config.action_view.javascript_expansions[:defaults] |= %w(flash jquery.cookie)
+ end
+ end
+
+ end
+end
View
36 lib/generators/cacheable_flash/install/install_generator.rb
@@ -0,0 +1,36 @@
+# encoding: utf-8
+
+module CacheableFlash
+ # Copies javascript libraries flash.js and jquery.cookie.js to public/javascripts/ (Rails 3.X only)
+ #
+ # @example
+ # $ rails generate cacheable_flash:install
+ #
+ # @todo Test with Rails 3.0
+ class InstallGenerator < Rails::Generators::Base
+ source_root File.expand_path('../../../templates', __FILE__)
+ class_option :template_engine
+
+ if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1
+ # Rails 3.1 has the asset pipeline, no need to copy CSS files any more
+ desc "Copies a config initializer to config/initializers/formtastic.rb"
+ def copy_files
+ copy_file 'formtastic.rb', 'config/initializers/formtastic.rb'
+ end
+ else
+ # Rails 3.0 doesn't have an asset pipeline, so we copy in CSS too
+ desc "Copies some CSS files to public/stylesheets/ and a config initializer to config/initializers/formtastic.rb"
+ def copy_files
+ template 'formtastic.rb', 'config/initializers/formtastic.rb'
+ template '../../../app/assets/stylesheets/formtastic.css', 'public/stylesheets/formtastic.css'
+ template '../../../app/assets/stylesheets/formtastic_ie6.css', 'public/stylesheets/formtastic_ie6.css'
+ template '../../../app/assets/stylesheets/formtastic_ie7.css', 'public/stylesheets/formtastic_ie7.css'
+ end
+ end
+
+ def copy_scaffold_template
+ engine = options[:template_engine]
+ copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
+ end
+ end
+end
View
2 spec/js_unit/flash_test.html
@@ -8,7 +8,7 @@
<script src="../../javascripts/jquery.js" type="text/javascript"></script>
<script src="../../javascripts/cookie.js" type="text/javascript"></script>
<script src="../../javascripts/json.js" type="text/javascript"></script>
- <script src="../../javascripts/flash.js" type="text/javascript"></script>
+ <script src="../../vendor/assets/flash.js" type="text/javascript"></script>
<script type="text/javascript">
Include.jsUnitCore();
Include.allProduction();
View
21 vendor/assets/flash.js
@@ -0,0 +1,21 @@
+// refactoring from https://github.com/leonid-shevtsov/cacheable-flash-jquery
+var Flash = new Object();
+
+Flash.data = {};
+
+Flash.transferFromCookies = function() {
+ var data = JSON.parse(unescape($.cookie("flash")));
+ if(!data) data = {};
+ Flash.data = data;
+ $.cookie('flash',null, {path: '/'});
+};
+
+Flash.writeDataTo = function(name, element) {
+ element = $(element);
+ var content = "";
+ if (Flash.data[name]) {
+ message = Flash.data[name].toString().replace(/\+/g, ' ');
+ element.html(message);
+ element.show();
+ }
+};
1 vendor/jquery-cookie
@@ -1 +0,0 @@
-Subproject commit c816cb31dd07b151b932b325b11f909bd4a2ff47

0 comments on commit 24d4c11

Please sign in to comment.