glow 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +70 -0
  3. data/Rakefile +23 -0
  4. data/lib/generators/glow/install/install_generator.rb +19 -0
  5. data/lib/glow.rb +8 -0
  6. data/lib/glow/engine.rb +10 -0
  7. data/lib/glow/filter.rb +19 -0
  8. data/lib/glow/railtie.rb +10 -0
  9. data/lib/glow/version.rb +3 -0
  10. data/lib/tasks/glow_tasks.rake +4 -0
  11. data/test/dummy/Gemfile +9 -0
  12. data/test/dummy/Gemfile.lock +124 -0
  13. data/test/dummy/Rakefile +7 -0
  14. data/test/dummy/app/assets/javascripts/application.js +9 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  16. data/test/dummy/app/controllers/application_controller.rb +3 -0
  17. data/test/dummy/app/controllers/flash_controller.rb +18 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/views/flash/ajax.js.erb +1 -0
  20. data/test/dummy/app/views/flash/show.html.erb +13 -0
  21. data/test/dummy/app/views/layouts/application.html.erb +18 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +43 -0
  24. data/test/dummy/config/boot.rb +8 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +24 -0
  28. data/test/dummy/config/environments/production.rb +51 -0
  29. data/test/dummy/config/environments/test.rb +38 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/inflections.rb +10 -0
  32. data/test/dummy/config/initializers/mime_types.rb +5 -0
  33. data/test/dummy/config/initializers/secret_token.rb +7 -0
  34. data/test/dummy/config/initializers/session_store.rb +8 -0
  35. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  36. data/test/dummy/config/locales/en.yml +5 -0
  37. data/test/dummy/config/routes.rb +6 -0
  38. data/test/dummy/db/development.sqlite3 +0 -0
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/dummy/log/development.log +1629 -0
  41. data/test/dummy/log/test.log +1035 -0
  42. data/test/dummy/public/404.html +26 -0
  43. data/test/dummy/public/422.html +26 -0
  44. data/test/dummy/public/500.html +26 -0
  45. data/test/dummy/public/favicon.ico +0 -0
  46. data/test/dummy/public/javascripts/glow.js +28 -0
  47. data/test/dummy/public/javascripts/jquery.js +8981 -0
  48. data/test/dummy/public/javascripts/jquery.min.js +18 -0
  49. data/test/dummy/public/javascripts/jquery_ujs.js +331 -0
  50. data/test/dummy/script/rails +6 -0
  51. data/test/dummy/spec/controllers/flash_controller_spec.rb +33 -0
  52. data/test/dummy/spec/integration/flash_spec.rb +17 -0
  53. data/test/dummy/spec/spec_helper.rb +31 -0
  54. data/test/dummy/tmp/pids/server.pid +1 -0
  55. metadata +180 -0
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Zweitag GmbH
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.
@@ -0,0 +1,70 @@
1
+ # Glow
2
+
3
+ Glowing flashes! Okay... not really. This simply adds handling of the
4
+ Fash Hash in Javascript. Depends on jQuery.
5
+
6
+ ## Usage
7
+
8
+ Any flash messages set in ajax responses fire a `glow:flash`
9
+ event on `document`.
10
+
11
+ flash[:notice] = 'Ajax man!'
12
+ respond_to do |format|
13
+ format.js { head :ok }
14
+ end
15
+
16
+ Handle it any way you want:
17
+
18
+ $(document).bind('glow:flash', function(evt, flash) {
19
+ alert(flash.type);
20
+ alert(flash.message);
21
+ }
22
+
23
+ Also adds a `Flash` object that enables you to fire `glow:flash`.
24
+
25
+ Flash.success('Yeah this worked!');
26
+ Flash.error('Something went wrong!');
27
+ Flash.notice('This is a flash message');
28
+
29
+ Flash.fire('type', 'message');
30
+
31
+ This can be used to unify your Flash message handling (also in non-xhr
32
+ responses).
33
+
34
+ <% flash.each |type, message| %>
35
+ <%= javascript_tag "Flash.fire('#{type}', '#{message}')" %>
36
+ <% end %>
37
+
38
+ ## Installation
39
+
40
+ In your gemfile add
41
+
42
+ gem "glow"
43
+
44
+ .
45
+
46
+ ### Rails 3.0
47
+
48
+ Run
49
+
50
+ rails generate glow:install
51
+
52
+ Then add
53
+
54
+ javascipt_include_tag 'glow'
55
+
56
+ to your layout.
57
+
58
+ ### Rails 3.1
59
+
60
+ TODO
61
+
62
+ ## License
63
+
64
+ See MIT-LICENSE.
65
+
66
+ ## TODO
67
+
68
+ - Test in 3.1
69
+ - Automatically add //= require glow to application.js in 3.1 (via
70
+ generator)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Glow'
18
+ rdoc.options << '--line-numbers'
19
+ #rdoc.rdoc_files.include('README.md')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,19 @@
1
+ require 'rails'
2
+
3
+ module Glow
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+
7
+ desc "This generator installs glow.js. You must inclu"
8
+ class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
9
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
10
+
11
+ def copy_glow
12
+ say_status("copying", "glow", :green)
13
+ copy_file "glow.js", "public/javascripts/glow.js"
14
+ say("Please include glow.js in your layout")
15
+ end
16
+
17
+ end
18
+ end
19
+ end if ::Rails.version < "3.1"
@@ -0,0 +1,8 @@
1
+ module Glow
2
+ if ::Rails.version < "3.1"
3
+ require 'glow/railtie'
4
+ else
5
+ require 'glow/engine'
6
+ end
7
+ require 'glow/version'
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'glow/filter'
2
+ require 'action_controller/base'
3
+
4
+ module Glow
5
+ class Railtie < Rails::Engine
6
+ config.to_prepare do
7
+ ::ActionController::Base.send :include, Glow::Filter
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'active_support/concern'
2
+
3
+ module Glow
4
+ module Filter
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ after_filter :flash_to_headers
8
+ end
9
+ module InstanceMethods
10
+ def flash_to_headers
11
+ return unless flash.any? && request.xhr?
12
+ type, message = flash.first
13
+ response.headers['X-Message'] = message.unpack('U*').map{ |i| "&##{i};" }.join
14
+ response.headers['X-Message-Type'] = type
15
+ flash.discard # don't want the flash to appear when you reload page
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'glow/filter'
2
+ require 'action_controller/base'
3
+
4
+ module Glow
5
+ class Railtie < Rails::Railtie
6
+ config.to_prepare do
7
+ ::ActionController::Base.send :include, Glow::Filter
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Glow
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :glow do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+ gem 'rails', "~> 3.0.0"
3
+ gem 'jquery-rails'
4
+ gem 'glow', path: '../..'
5
+ #group :test, :development do
6
+ gem 'rspec-rails'
7
+ gem 'capybara'
8
+ gem 'htmlentities'
9
+ #end
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ glow (0.0.1)
5
+ jquery-rails
6
+ rails (~> 3.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.10)
13
+ actionpack (= 3.0.10)
14
+ mail (~> 2.2.19)
15
+ actionpack (3.0.10)
16
+ activemodel (= 3.0.10)
17
+ activesupport (= 3.0.10)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.5.0)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.14)
23
+ rack-test (~> 0.5.7)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.10)
26
+ activesupport (= 3.0.10)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.5.0)
29
+ activerecord (3.0.10)
30
+ activemodel (= 3.0.10)
31
+ activesupport (= 3.0.10)
32
+ arel (~> 2.0.10)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.10)
35
+ activemodel (= 3.0.10)
36
+ activesupport (= 3.0.10)
37
+ activesupport (3.0.10)
38
+ arel (2.0.10)
39
+ builder (2.1.2)
40
+ capybara (1.0.1)
41
+ mime-types (>= 1.16)
42
+ nokogiri (>= 1.3.3)
43
+ rack (>= 1.0.0)
44
+ rack-test (>= 0.5.4)
45
+ selenium-webdriver (~> 2.0)
46
+ xpath (~> 0.1.4)
47
+ childprocess (0.2.1)
48
+ ffi (~> 1.0.6)
49
+ diff-lcs (1.1.3)
50
+ erubis (2.6.6)
51
+ abstract (>= 1.0.0)
52
+ ffi (1.0.9)
53
+ htmlentities (4.3.0)
54
+ i18n (0.5.0)
55
+ jquery-rails (1.0.13)
56
+ railties (~> 3.0)
57
+ thor (~> 0.14)
58
+ json_pure (1.5.3)
59
+ mail (2.2.19)
60
+ activesupport (>= 2.3.6)
61
+ i18n (>= 0.4.0)
62
+ mime-types (~> 1.16)
63
+ treetop (~> 1.4.8)
64
+ mime-types (1.16)
65
+ nokogiri (1.5.0)
66
+ polyglot (0.3.2)
67
+ rack (1.2.3)
68
+ rack-mount (0.6.14)
69
+ rack (>= 1.0.0)
70
+ rack-test (0.5.7)
71
+ rack (>= 1.0)
72
+ rails (3.0.10)
73
+ actionmailer (= 3.0.10)
74
+ actionpack (= 3.0.10)
75
+ activerecord (= 3.0.10)
76
+ activeresource (= 3.0.10)
77
+ activesupport (= 3.0.10)
78
+ bundler (~> 1.0)
79
+ railties (= 3.0.10)
80
+ railties (3.0.10)
81
+ actionpack (= 3.0.10)
82
+ activesupport (= 3.0.10)
83
+ rake (>= 0.8.7)
84
+ rdoc (~> 3.4)
85
+ thor (~> 0.14.4)
86
+ rake (0.9.2)
87
+ rdoc (3.9.3)
88
+ rspec (2.6.0)
89
+ rspec-core (~> 2.6.0)
90
+ rspec-expectations (~> 2.6.0)
91
+ rspec-mocks (~> 2.6.0)
92
+ rspec-core (2.6.4)
93
+ rspec-expectations (2.6.0)
94
+ diff-lcs (~> 1.1.2)
95
+ rspec-mocks (2.6.0)
96
+ rspec-rails (2.6.1)
97
+ actionpack (~> 3.0)
98
+ activesupport (~> 3.0)
99
+ railties (~> 3.0)
100
+ rspec (~> 2.6.0)
101
+ rubyzip (0.9.4)
102
+ selenium-webdriver (2.4.0)
103
+ childprocess (>= 0.2.1)
104
+ ffi (>= 1.0.7)
105
+ json_pure
106
+ rubyzip
107
+ thor (0.14.6)
108
+ treetop (1.4.10)
109
+ polyglot
110
+ polyglot (>= 0.3.1)
111
+ tzinfo (0.3.29)
112
+ xpath (0.1.4)
113
+ nokogiri (~> 1.3)
114
+
115
+ PLATFORMS
116
+ ruby
117
+
118
+ DEPENDENCIES
119
+ capybara
120
+ glow!
121
+ htmlentities
122
+ jquery-rails
123
+ rails (~> 3.0.0)
124
+ rspec-rails
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -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 .
@@ -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
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,18 @@
1
+ class FlashController < ApplicationController
2
+ def show
3
+ # show.html.erb
4
+ end
5
+
6
+ def redirect
7
+ flash[params[:type]] = params[:message]
8
+ redirect_to action: 'show'
9
+ end
10
+
11
+ def ajax
12
+ respond_to do |wants|
13
+ wants.js {
14
+ flash[params[:type]] = params[:message]
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1 @@
1
+ console.log('ajax response');
@@ -0,0 +1,13 @@
1
+ <script type="application/javascript">
2
+ // Flash handling
3
+ $(document).bind('glow:flash', function(evt, flash) { console.log('glow flash'); $('#flash').html(flash.message); });
4
+ </script>
5
+
6
+ <p id="flash"><%= flash.map { |type, message| message }.join %></p>
7
+ <p><%= link_to 'redirect', action: :redirect, type: :notice, message: 'utf8: ✓ ' %></p>
8
+ <p><%= link_to 'rails ajax', {action: :ajax, type: :notice, message: 'rails ajax: ✓ '}, remote: true %></p>
9
+ <p><%= link_to 'jquery ajax', '#', id: 'ajax' %></p>
10
+
11
+ <script type="application/javascript">
12
+ $('#ajax').click(function(){$.get('<%= url_for action: :ajax, type: :notice, message: 'jquery utf8: ✓', format: :js %>'); return false;});
13
+ </script>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%=
6
+ #stylesheet_link_tag "application"
7
+ %>
8
+ <%= javascript_include_tag :defaults, 'glow' %>
9
+ <%=
10
+ #csrf_meta_tags
11
+ %>
12
+ </head>
13
+ <body>
14
+
15
+ <%= yield %>
16
+
17
+ </body>
18
+ </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,43 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "active_resource/railtie"
5
+ require "rails/test_unit/railtie"
6
+
7
+ Bundler.require
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # Configure the default encoding used in templates for Ruby 1.9.
34
+ config.encoding = "utf-8"
35
+
36
+ # Configure sensitive parameters which will be filtered from the log file.
37
+ config.filter_parameters += [:password]
38
+
39
+ # Enable the asset pipeline
40
+ # config.assets.enabled = true
41
+ end
42
+ end
43
+