edifice-widgets 0.1.0

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 (37) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.md +124 -0
  4. data/Rakefile +7 -0
  5. data/app/assets/javascripts/edifice-widgets/hooks.js +16 -0
  6. data/app/assets/javascripts/edifice-widgets/traits.js +31 -0
  7. data/app/assets/javascripts/edifice-widgets/widgets.js +107 -0
  8. data/app/assets/javascripts/edifice-widgets.js +5 -0
  9. data/edifice-widgets.gemspec +26 -0
  10. data/lib/edifice-widgets/version.rb +5 -0
  11. data/lib/edifice-widgets.rb +9 -0
  12. data/spec/rails3.1/.gitignore +5 -0
  13. data/spec/rails3.1/app/assets/images/rails.png +0 -0
  14. data/spec/rails3.1/app/assets/javascripts/application.js +15 -0
  15. data/spec/rails3.1/app/assets/javascripts/traits.js +5 -0
  16. data/spec/rails3.1/app/assets/javascripts/widgets.js +5 -0
  17. data/spec/rails3.1/app/assets/stylesheets/application.css +7 -0
  18. data/spec/rails3.1/app/controllers/application_controller.rb +3 -0
  19. data/spec/rails3.1/app/controllers/test_controller.rb +2 -0
  20. data/spec/rails3.1/app/views/layouts/application.html.erb +14 -0
  21. data/spec/rails3.1/app/views/test/ajax.html.erb +2 -0
  22. data/spec/rails3.1/app/views/test/base.html.erb +4 -0
  23. data/spec/rails3.1/config/application.rb +55 -0
  24. data/spec/rails3.1/config/boot.rb +6 -0
  25. data/spec/rails3.1/config/environment.rb +5 -0
  26. data/spec/rails3.1/config/environments/test.rb +35 -0
  27. data/spec/rails3.1/config/initializers/backtrace_silencers.rb +7 -0
  28. data/spec/rails3.1/config/initializers/inflections.rb +10 -0
  29. data/spec/rails3.1/config/initializers/mime_types.rb +5 -0
  30. data/spec/rails3.1/config/initializers/secret_token.rb +7 -0
  31. data/spec/rails3.1/config/initializers/session_store.rb +8 -0
  32. data/spec/rails3.1/config/initializers/wrap_parameters.rb +14 -0
  33. data/spec/rails3.1/config/routes.rb +4 -0
  34. data/spec/rails3.1/log/.gitkeep +0 -0
  35. data/spec/spec_helper.rb +7 -0
  36. data/spec/widgets_and_traits_spec.rb +43 -0
  37. metadata +209 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in edifice-widgets.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ Edifice Widgets + Traits
2
+ ========================
3
+
4
+ Edifice-widgets is a companion gem to [edifice](/tmeasday/edifice) which allows simple unobtrusive javascript behaviours, allowing you to make pages dynamic, whilst avoiding unnecessary boilerplate.
5
+
6
+ Note that it does not depend on edifice although it complements it well. Also note that it doesn't depend on rails---the javascript files can be used in isolation if you want. It does depend on jQuery.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ To install, simply add to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'edifice-widgets'
15
+ ```
16
+
17
+
18
+ To include the javascript, add to your application.js:
19
+
20
+ ```js
21
+ /*
22
+ *= require edifice-widgets
23
+ */
24
+ ```
25
+
26
+ Traits -- unobtrusive JS behaviours
27
+ -----------------------------------
28
+
29
+ Traits are best explained through example. Suppose you have a input field that you'd like to automatically select all when clicked on (for example github's repository URL field). If we define:
30
+
31
+ ```javascript
32
+ $.edifice_traits.always_select_all = function() {
33
+ return this.bind('click select focus focusin', function() {
34
+ this.select();
35
+ });
36
+ }
37
+ ```
38
+
39
+ Then we can use such a behaviour with:
40
+
41
+ ```html
42
+ <input data-trait="always_select_all">
43
+ ```
44
+
45
+ edifice-widgets will ensure that the code is attached to the `input` and everything behaves as you'd expect.
46
+
47
+ You can define more than one trait for an element (separate them with spaces, as you would CSS classes). For that reason, as a rule, it is best if traits remain very simple, and don't alter the internal HTML structure of the element. Otherwise bugs are bound to happen when you combine them.
48
+
49
+ Widgets -- unobtrusive specialised elements
50
+ -------------------------------------------
51
+
52
+ If you need something more complex that will significantly alter the HTML, or which requires arguments, it is best to use a widget. For example, suppose you want to create a styled separatelect. Suppose we want to use it all over our website.
53
+
54
+ Then we want to write the minimum of HTML above what we would to use a vanilla select, and let the JS framework take care of hooking things together. edifice-widgets lets us write simply:
55
+
56
+ ```html
57
+ <select name="country" data-widget="select">
58
+ <option value="au">Australia</option>
59
+ <option value="us">USA</option>
60
+ </select>
61
+ ```
62
+
63
+ To enable this, we can write a `select` widget, which goes something like:
64
+
65
+ ```js
66
+ // note this is basically untested psuedo-code, don't use on production please
67
+ $.edifice_widgets.select = function() {
68
+ return this.each(function(){
69
+ var $select = $(this).wrap('<div class="select">'),
70
+ $widget = $select.parent(), $ul = $('<ul>').insertBefore($select);
71
+
72
+ // insert the selected text
73
+ $widget.prepend('<a class="selected">' + $select.val() + '</a>');
74
+
75
+ $select.find('option').each(function() {
76
+ // add a <li> to $ul
77
+ var $li = $('<li">' + $(this).text() + '</li>').data('option', $(this));
78
+ $ul.append();
79
+ });
80
+
81
+ // bind click events on lis to select the li's value and close the select widget
82
+ $widget.delegate('li', 'click', function() {
83
+ $select.val($(this).data('option').val());
84
+ $widget.find('.selected').text($(this).data('option').text());
85
+ $widget.removeClass('open');
86
+
87
+ // bind click events on the selected value to toggle the open state
88
+ }).delegate('.selected', 'click', function() {
89
+ $widget.toggleClass('open');
90
+ })
91
+ });
92
+ }
93
+ ```
94
+
95
+ Of course you would also need to define some appropriate styles to make the select look right.
96
+
97
+ Widgets can take arguments, which are set like so:
98
+
99
+ ```html
100
+ <select data-widget="select" data-widget-open_class="expanded">
101
+ ```
102
+
103
+ To access the option easily, use the `.read_options` method:
104
+
105
+ ```js
106
+ var settings = $(this).read_options({
107
+ 'open_class': 'open' // <-- this is the default value for settings.open_class
108
+ })
109
+ ```
110
+
111
+ Use `$edifice_widgets.REQUIRED` to indicate that a setting is required:
112
+
113
+ ```js
114
+ var settings = $(this).read_options({
115
+ 'autosubmit_url': $.edifice_widgets.REQUIRED
116
+ });
117
+ ```
118
+
119
+
120
+ License
121
+ -------
122
+
123
+ Edifice is crafted by [Percolate Studio](http://percolatestudio.com) and released under the [MIT license](www.opensource.org/licenses/MIT)
124
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ (function($) {
2
+ // code that automatically hooks up the traits + widgets defined in the edifice namespace
3
+
4
+ // when the document is ready, we can attach widgets
5
+ $(document).ready(function() {
6
+ $('body').attach_widgets().attach_traits();
7
+ $(document).trigger('widgetsReady');
8
+
9
+ // whenever an ajax request completes, we want to attach any widgets that have been attached to do the dom
10
+ $('body').ajaxComplete(function(event, request) {
11
+ $('body').attach_widgets().attach_traits();
12
+ $(document).trigger('widgetsReady');
13
+ });
14
+ });
15
+
16
+ }(jQuery));
@@ -0,0 +1,31 @@
1
+ (function($) {
2
+ // *********** EDIFICE TRAIT CODE ************ //
3
+
4
+ /**
5
+ @name $.edifice_traits
6
+ @namespace
7
+ @description Traits live here.
8
+ */
9
+ $.edifice_traits = {};
10
+
11
+ /**
12
+ * Runs $.edifice.traits.X on all contained elements with data-trait containing X
13
+ *
14
+ * @param {Boolean} Reset the checks to see if things have already been attached
15
+ * [use this if you have clone an element without copying events]
16
+ *
17
+ * Records which elements have already been 'traited' via data-trait-attached
18
+ */
19
+ $.fn.attach_traits = function(reset) {
20
+ if (reset) { this.find('[data-trait]').removeAttr('data-trait-attached'); }
21
+
22
+ for (trait in $.edifice_traits) {
23
+ var $els = this.find('[data-trait~=' + trait + ']:not([data-trait-attached~=' + trait + '])');
24
+ $els.attr('data-trait-attached', function(i, val) {
25
+ return (val ? val + ' ' : '') + trait;
26
+ });
27
+ $.edifice_traits[trait].call($els);
28
+ }
29
+ return this;
30
+ }
31
+ }(jQuery));
@@ -0,0 +1,107 @@
1
+ (function($) {
2
+ // *********** EDIFICE WIDGET CODE *********** //
3
+ /**
4
+ @name $.edifice_widgets
5
+ @namespace
6
+ @description Our widgets live here.
7
+ */
8
+ $.edifice_widgets = {};
9
+
10
+ /**
11
+ * Runs attach_widget() on any widget found in the html which isn't already attached.
12
+ *
13
+ * @param {Boolean} Reset the checks to see if things have already been attached
14
+ * [use this if you have clone an element without copying events]
15
+ *
16
+ */
17
+ $.fn.attach_widgets = function(reset) {
18
+ if (reset) { this.find('[data-widget]').removeAttr('data-widget-attached'); }
19
+
20
+ this.find('[data-widget]:not([data-widget-attached])').attach_widget();
21
+
22
+ return this;
23
+ };
24
+
25
+ /**
26
+ * Call $.WIDGET_NAME on the matched elements where WIDGET_NAME is set in the
27
+ * data-widget attribute.
28
+ *
29
+ * @param {Object} extra_options Use these options in addition to those specified
30
+ * in the html as data-widget-OPTION_NAME=VALUE
31
+ *
32
+ * @throws {Exception} If a widget has already been attached.
33
+ * @throws {Exception} If the type of widget doesn't exist.
34
+ */
35
+ $.fn.attach_widget = function(extra_options) {
36
+ return this.each(function() {
37
+ var $e = $(this), fn_name = $e.attr('data-widget');
38
+
39
+ // error checking
40
+ if ($e.attr('data-widget-attached')) {
41
+ throw('attach_widget called on already attached widget.');
42
+ }
43
+ if (!(fn_name in $.edifice_widgets)) {
44
+ throw("edifice widget '" + fn_name + "' is not defined.");
45
+ }
46
+
47
+ // attach extra options to the widget
48
+ if (typeof(extra_options) != 'undefined') {
49
+ $.each(extra_options, function(name, def) {
50
+ $e.data('widget-' + name, def);
51
+ });
52
+ }
53
+
54
+ // load the widget up
55
+ $.edifice_widgets[fn_name].call($e);
56
+ $e.attr('data-widget-attached', true);
57
+ });
58
+ };
59
+
60
+ /**
61
+ * Make a widget out of an element which doesn't already have data-widget set
62
+ * in the html.
63
+ *
64
+ * @param {String} Type Type of widget, e.g 'ajax_form'
65
+ * @param {Object} Options for widget.
66
+ */
67
+ $.fn.create_widget = function(type, options) {
68
+ return $(this).attr('data-widget', type).attach_widget(options);
69
+ };
70
+
71
+ /**
72
+ * @constant
73
+ */
74
+ $.edifice_widgets.REQUIRED = '*** VALUE REQUIRED ***';
75
+
76
+ /**
77
+ * Read the set of options attached to a widget via data-widget-OPTION_NAME
78
+ * in the html.
79
+ *
80
+ * @param {Object} defaults Specifies the names and default values of
81
+ * applicable options. Set default value to $.edifice_widgets.REQUIRED to indicate
82
+ * a mandatory value.
83
+ *
84
+ * @returns {Object} The options calculated.
85
+ *
86
+ * @throws {Exception} If a required option is not found.
87
+ */
88
+ $.fn.read_options = function(defaults) {
89
+ var that = this;
90
+ var options = {};
91
+ $.each(defaults, function(name, def) {
92
+ var val = that.data('widget-' + name) || that.attr('data-widget-' + name);
93
+
94
+ if (val) {
95
+ options[name] = val;
96
+ } else {
97
+ if (def === $.edifice_widgets.REQUIRED) {
98
+ throw("Widget argument required: " + name);
99
+ }
100
+
101
+ options[name] = def;
102
+ }
103
+ });
104
+
105
+ return options;
106
+ }
107
+ }(jQuery));
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require edifice-widgets/widgets.js
3
+ *= require edifice-widgets/traits.js
4
+ *= require edifice-widgets/hooks.js
5
+ */
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "edifice-widgets/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "edifice-widgets"
7
+ s.version = Edifice::Widgets::VERSION
8
+ s.authors = ["Tom Coleman"]
9
+ s.email = ["tom@thesnail.org"]
10
+ s.homepage = "http://edifice-rails.com"
11
+ s.summary = %q{Edifice-widgets is a companion gem to edifice which allows simple unobtrusive javascript behaviours.}
12
+ s.description = %q{Edifice-widgets is a companion gem to edifice which allows simple unobtrusive javascript behaviours, allowing you to make pages dynamic, whilst avoiding unnecessary boilerplate.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency 'jquery-rails'
20
+
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'rails'
23
+ s.add_development_dependency 'rspec-rails'
24
+ s.add_development_dependency 'capybara'
25
+ s.add_development_dependency 'tzinfo'
26
+ end
@@ -0,0 +1,5 @@
1
+ module Edifice
2
+ module Widgets
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "edifice-widgets/version"
2
+
3
+ # so JS files can be *= required
4
+ module Edifice
5
+ module Widgets
6
+ class Engine < Rails::Engine
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
5
+ .sass-cache/
@@ -0,0 +1,15 @@
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 edifice-widgets
9
+ //= require_tree .
10
+
11
+ (function($) {
12
+ $(document).bind('widgetsReady', function() {
13
+ $('body').append('<h1 class="widgetsReady">widgets ready<h1>');
14
+ })
15
+ }(jQuery));
@@ -0,0 +1,5 @@
1
+ (function($) {
2
+ $.edifice_widgets.test_trait = function() {
3
+ this.append('<div class="trait_loaded">');
4
+ }
5
+ }(jQuery));
@@ -0,0 +1,5 @@
1
+ (function($) {
2
+ $.edifice_widgets.test_widget = function() {
3
+ this.append('<div class="widget_loaded">widgets loaded</div>');
4
+ }
5
+ }(jQuery));
@@ -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,2 @@
1
+ class TestController < ApplicationController
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Rails31</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ <div data-widget="test_widget"></div>
2
+ <div data-widget="test_trait"></div>
@@ -0,0 +1,4 @@
1
+ <div data-widget="test_widget"></div>
2
+ <div data-widget="test_trait"></div>
3
+
4
+ <div id="ajax"></div>
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "sprockets/railtie"
5
+
6
+ require 'jquery-rails'
7
+
8
+
9
+ if defined?(Bundler)
10
+ # If you precompile assets before deploying to production, use this line
11
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
12
+ # If you want your assets lazily compiled in production, use this line
13
+ # Bundler.require(:default, :assets, Rails.env)
14
+ end
15
+
16
+ module Rails31
17
+ class Application < Rails::Application
18
+ # don't know how i was supposed to set this
19
+ config.root = ENV['RAILS_ROOT']
20
+
21
+ # Settings in config/environments/* take precedence over those specified here.
22
+ # Application configuration should go into files in config/initializers
23
+ # -- all .rb files in that directory are automatically loaded.
24
+
25
+ # Custom directories with classes and modules you want to be autoloadable.
26
+ # config.autoload_paths += %W(#{config.root}/extras)
27
+
28
+ # Only load the plugins named here, in the order given (default is alphabetical).
29
+ # :all can be used as a placeholder for all plugins not explicitly named.
30
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
31
+
32
+ # Activate observers that should always be running.
33
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
34
+
35
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
36
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
37
+ # config.time_zone = 'Central Time (US & Canada)'
38
+
39
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
40
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
41
+ # config.i18n.default_locale = :de
42
+
43
+ # Configure the default encoding used in templates for Ruby 1.9.
44
+ config.encoding = "utf-8"
45
+
46
+ # Configure sensitive parameters which will be filtered from the log file.
47
+ config.filter_parameters += [:password]
48
+
49
+ # Enable the asset pipeline
50
+ config.assets.enabled = true
51
+
52
+ # Version of your assets, change this if you want to expire all your assets
53
+ config.assets.version = '1.0'
54
+ end
55
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Rails31::Application.initialize!
@@ -0,0 +1,35 @@
1
+ Rails31::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
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
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
+ Rails31::Application.config.secret_token = '9c49a20f1a1927d39445006fa86e869792e085b10f0a4f0c8301cd50207d8beca37dd1f3c641522d4411528c87cbf50827cccf7f89e51529be1b4c71a7d7d7bc'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails31::Application.config.session_store :cookie_store, :key => '_rails3.1_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
+ # Rails31::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters :format => [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,4 @@
1
+ Rails31::Application.routes.draw do
2
+ match "test/base" => 'test#base'
3
+ match "test/ajax" => 'test#ajax'
4
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] = File.join(File.dirname(__FILE__), 'rails3.1')
3
+
4
+ require File.expand_path('config/environment', ENV['RAILS_ROOT'])
5
+
6
+ require 'rspec/rails'
7
+ require 'capybara/rails'
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'widgets and traits', :type => :request, :js => true do
4
+ it "should fire widgetsReady" do
5
+ visit('/test/base')
6
+
7
+ page.should have_selector('h1.widgetsReady')
8
+ end
9
+
10
+ it "should fire widgetsReady on ajax" do
11
+ visit('/test/base')
12
+ page.should have_selector('h1.widgetsReady')
13
+
14
+ page.evaluate_script('jQuery.get("/test/ajax")')
15
+ page.should have_selector('h1.widgetsReady', :count => 2)
16
+ end
17
+
18
+ it "should hook up widgets" do
19
+ visit('/test/base')
20
+
21
+ page.should have_selector('.widget_loaded')
22
+ end
23
+
24
+ it "should hook up traits" do
25
+ visit('/test/base')
26
+
27
+ page.should have_selector('.trait_loaded')
28
+ end
29
+
30
+ it "should hook up widgets on ajax" do
31
+ visit('/test/base')
32
+ page.evaluate_script('jQuery.get("/test/ajax", function(d) { jQuery("#ajax").append(d); })')
33
+
34
+ page.should have_selector('#ajax .widget_loaded')
35
+ end
36
+
37
+ it "should hook up traits on ajax" do
38
+ visit('/test/base')
39
+ page.evaluate_script('jQuery.get("/test/ajax", function(d) { jQuery("#ajax").append(d); })')
40
+
41
+ page.should have_selector('#ajax .trait_loaded')
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edifice-widgets
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Tom Coleman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-22 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: jquery-rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rails
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: capybara
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: tzinfo
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id006
104
+ description: Edifice-widgets is a companion gem to edifice which allows simple unobtrusive javascript behaviours, allowing you to make pages dynamic, whilst avoiding unnecessary boilerplate.
105
+ email:
106
+ - tom@thesnail.org
107
+ executables: []
108
+
109
+ extensions: []
110
+
111
+ extra_rdoc_files: []
112
+
113
+ files:
114
+ - .gitignore
115
+ - Gemfile
116
+ - README.md
117
+ - Rakefile
118
+ - app/assets/javascripts/edifice-widgets.js
119
+ - app/assets/javascripts/edifice-widgets/hooks.js
120
+ - app/assets/javascripts/edifice-widgets/traits.js
121
+ - app/assets/javascripts/edifice-widgets/widgets.js
122
+ - edifice-widgets.gemspec
123
+ - lib/edifice-widgets.rb
124
+ - lib/edifice-widgets/version.rb
125
+ - spec/rails3.1/.gitignore
126
+ - spec/rails3.1/app/assets/images/rails.png
127
+ - spec/rails3.1/app/assets/javascripts/application.js
128
+ - spec/rails3.1/app/assets/javascripts/traits.js
129
+ - spec/rails3.1/app/assets/javascripts/widgets.js
130
+ - spec/rails3.1/app/assets/stylesheets/application.css
131
+ - spec/rails3.1/app/controllers/application_controller.rb
132
+ - spec/rails3.1/app/controllers/test_controller.rb
133
+ - spec/rails3.1/app/views/layouts/application.html.erb
134
+ - spec/rails3.1/app/views/test/ajax.html.erb
135
+ - spec/rails3.1/app/views/test/base.html.erb
136
+ - spec/rails3.1/config/application.rb
137
+ - spec/rails3.1/config/boot.rb
138
+ - spec/rails3.1/config/environment.rb
139
+ - spec/rails3.1/config/environments/test.rb
140
+ - spec/rails3.1/config/initializers/backtrace_silencers.rb
141
+ - spec/rails3.1/config/initializers/inflections.rb
142
+ - spec/rails3.1/config/initializers/mime_types.rb
143
+ - spec/rails3.1/config/initializers/secret_token.rb
144
+ - spec/rails3.1/config/initializers/session_store.rb
145
+ - spec/rails3.1/config/initializers/wrap_parameters.rb
146
+ - spec/rails3.1/config/routes.rb
147
+ - spec/rails3.1/log/.gitkeep
148
+ - spec/spec_helper.rb
149
+ - spec/widgets_and_traits_spec.rb
150
+ homepage: http://edifice-rails.com
151
+ licenses: []
152
+
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.8.10
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Edifice-widgets is a companion gem to edifice which allows simple unobtrusive javascript behaviours.
183
+ test_files:
184
+ - spec/rails3.1/.gitignore
185
+ - spec/rails3.1/app/assets/images/rails.png
186
+ - spec/rails3.1/app/assets/javascripts/application.js
187
+ - spec/rails3.1/app/assets/javascripts/traits.js
188
+ - spec/rails3.1/app/assets/javascripts/widgets.js
189
+ - spec/rails3.1/app/assets/stylesheets/application.css
190
+ - spec/rails3.1/app/controllers/application_controller.rb
191
+ - spec/rails3.1/app/controllers/test_controller.rb
192
+ - spec/rails3.1/app/views/layouts/application.html.erb
193
+ - spec/rails3.1/app/views/test/ajax.html.erb
194
+ - spec/rails3.1/app/views/test/base.html.erb
195
+ - spec/rails3.1/config/application.rb
196
+ - spec/rails3.1/config/boot.rb
197
+ - spec/rails3.1/config/environment.rb
198
+ - spec/rails3.1/config/environments/test.rb
199
+ - spec/rails3.1/config/initializers/backtrace_silencers.rb
200
+ - spec/rails3.1/config/initializers/inflections.rb
201
+ - spec/rails3.1/config/initializers/mime_types.rb
202
+ - spec/rails3.1/config/initializers/secret_token.rb
203
+ - spec/rails3.1/config/initializers/session_store.rb
204
+ - spec/rails3.1/config/initializers/wrap_parameters.rb
205
+ - spec/rails3.1/config/routes.rb
206
+ - spec/rails3.1/log/.gitkeep
207
+ - spec/spec_helper.rb
208
+ - spec/widgets_and_traits_spec.rb
209
+ has_rdoc: