motr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,9 +5,18 @@ gem "capybara", ">= 0.4.0"
5
5
  gem "sqlite3-ruby"
6
6
  gem "rspec-rails"
7
7
  gem "mocha","0.9.12"
8
+ gem "minitest"
9
+
10
+ group :mongoid do
11
+ gem 'mongo', '~> 1.3'
12
+ gem 'bson_ext', '~> 1.3'
13
+ gem 'mongoid', '~> 2.0'
14
+ end
8
15
 
9
16
  group :test do
17
+ gem "colored"
18
+ gem 'shoulda-context'
10
19
  gem 'fabrication', '0.9.5'
11
20
  gem 'ffaker', '1.5.0'
12
- gem 'spork', '~> 0.9.0.rc'
21
+ gem 'spork', '~> 0.9.0.rc', :require => false
13
22
  end
data/README.rdoc CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  {Official Documentation}[http://rubydoc.info/github/kurbmedia/motr/master/frames]
4
4
 
5
- Motr is a basic Rails engine which adds additional functionality to your applications. The {core Motr}[http://github.com/kurbmedia/motr] engine
6
- provides a number of helpers and functionality geared towards bringing the ease of Rails back-end development, to the front-end.
5
+ Motr is a basic Rails engine which adds additional functionality to your applications, and creates the ability to "extend" models
6
+ easily to support routine functionality. The {core Motr}[http://github.com/kurbmedia/motr] engine
7
+ provides a number of helpers and functionality geared towards bringing the ease of Rails back-end development, to the front-end. It
8
+ also implements a {Devise}[https://github.com/plataformatec/devise] inspired "hook" system to support easily adding data functionality to
9
+ models in a similar manner to how Devise adds session management functionality.
7
10
 
8
11
  Rails view helpers and form builders are convenient an easy to use, however some aren't very design/html friendly (whose idea was it to
9
12
  wrap fields with errors in a div?). The goal is to keep html valid and sensible where possible, and make things like javascript integration
@@ -18,6 +21,10 @@ Motr is maintained and funded by {kurb media}[http://kurbmedia.com/], and was de
18
21
  opinionated in how it works. However, additions / enhancements / alternative methods are more than welcome and encouraged. We also welcome
19
22
  feature requests, especially from designers/front-end developers who spend a lot of time working along-side Rails developers.
20
23
 
24
+ == Credits
25
+
26
+ Thanks to José Valim and {Devise}[https://github.com/plataformatec/devise] which inspired the model hook functionality.
27
+
21
28
  == License
22
29
 
23
30
  Motr is Copyright © 2010-2011 kurb media, llc.
data/Rakefile CHANGED
@@ -13,11 +13,19 @@ require 'rake/rdoctask'
13
13
 
14
14
  require 'rspec/core'
15
15
  require 'rspec/core/rake_task'
16
+ require 'rake/testtask'
16
17
 
17
18
  RSpec::Core::RakeTask.new(:spec)
18
19
 
19
20
  task :default => :spec
20
21
 
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+
21
29
  Rake::RDocTask.new(:rdoc) do |rdoc|
22
30
  rdoc.rdoc_dir = 'rdoc'
23
31
  rdoc.title = 'motr'
@@ -1,8 +1,2 @@
1
1
  module MotrHelper #:nodoc:
2
-
3
- include Motr::Helpers::LayoutHelpers
4
- include Motr::Helpers::Navigation
5
- include Motr::Helpers::Elements
6
- include Motr::Forms::Helpers
7
-
8
2
  end
data/lib/motr.rb CHANGED
@@ -3,35 +3,83 @@ require 'active_support/dependencies'
3
3
  require 'set'
4
4
 
5
5
  require 'motr/forms'
6
+ require 'motr/model'
6
7
 
7
8
  module Motr
8
-
9
- module Controller
10
- autoload :Responder, 'motr/controller/responder'
11
- autoload :ScriptEvents, 'motr/controller/script_events'
9
+
10
+ module Controller #:nodoc:
11
+ autoload :Helpers, 'motr/controller/helpers'
12
+ autoload :Responder, 'motr/controller/responder'
12
13
  end
13
-
14
- module Helpers
14
+
15
+ module Helpers #:nodoc:
15
16
  autoload :LayoutHelpers, 'motr/helpers/layout_helpers'
16
17
  autoload :Navigation, 'motr/helpers/navigation'
17
18
  autoload :Elements, 'motr/helpers/elements'
18
19
  end
19
20
 
20
- module Errors
21
+ module Errors #:nodoc:
21
22
  autoload :MotrError, 'motr/errors/motr_error'
22
23
  autoload :InvalidOptions, 'motr/errors/invalid_options'
24
+ autoload :ModuleMissing, 'motr/errors/module_missing'
25
+ end
26
+
27
+ # Store configurations for included models
28
+ ALL = []
29
+ CONFIGS = {}
30
+
31
+ ##
32
+ #
33
+ # Enable adding models to the core Motr library. These modules
34
+ # can then be included/initialized using the +motr+ method.
35
+ #
36
+ # @param [Symbol] module_name The name of the module to be added (underscored)
37
+ # @param [Hash] config Default configuration options for the module
38
+ #
39
+ # @option config [String, Boolean] :autoload The path to autoload the module from (optional)
40
+ #
41
+ # All other configuration options are considered default options for that particular module.
42
+ #
43
+ #
44
+ def self.add_module(module_name, config = {})
45
+
46
+ # Store a reference to any module loaded
47
+ ALL << module_name
48
+ config.assert_valid_keys(:autoload)
49
+
50
+ const_name = ActiveSupport::Inflector.camelize(module_name.to_s)
51
+
52
+ # Setup autoloading for this module if necessary
53
+ if autoload_path = config.delete(:autoload)
54
+ path = (autoload_path == true ? "motr/model/#{module_name.to_s}" : autoload_path)
55
+ Motr::Model.send(:autoload, const_name, path)
56
+ end
57
+
58
+ # Setup placeholder for configuration
59
+ Motr::CONFIGS[module_name] ||= {}
60
+
61
+ # Setup configuration method for module.
62
+ #
63
+ self.class_eval <<-METHOD, __FILE__, __LINE__ + 1
64
+ def self.#{module_name.to_s}(options = {})
65
+ raise Motr::Errors::InvalidOptions.new('Configuration for #{module_name} must be a hash.') unless options.is_a?(Hash)
66
+ Motr::CONFIGS[:#{module_name.to_s}].merge!(options)
67
+ end
68
+ METHOD
69
+
70
+ # Apply any defaults
71
+ Motr.send(:"#{module_name}", config)
72
+
23
73
  end
24
74
 
25
75
  # Support initializer configuration
76
+ # @private
77
+ #
26
78
  def self.configure #:nodoc:
27
79
  yield self
28
80
  end
29
81
 
30
- # Support configuration of the forms module
31
- def self.forms #:nodoc:
32
- yield Motr::Forms
33
- end
34
-
35
82
  end
36
83
 
84
+ require 'motr/defaults'
37
85
  require 'motr/rails'
@@ -0,0 +1,83 @@
1
+ require 'action_controller/base'
2
+
3
+ module Motr
4
+ module Controller
5
+
6
+ module Helpers
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ after_filter :generate_ajax_headers
11
+ class_attribute :response_metadata
12
+ self.response_metadata = {}
13
+ end
14
+
15
+ ##
16
+ # Generates additional header information for ajax requests, to allow more flexibility in
17
+ # handling responses. It simply creates a X-Response-Meta header in the response which contains
18
+ # a json object representing the requested controller and action name, as well as any user defined metadata set with +add_response_meta+
19
+ #
20
+ # @see Motr#Controller#Helpers#add_response_meta
21
+ # @private
22
+ #
23
+ def generate_ajax_headers #:nodoc:
24
+ return true unless response.content_type.to_s.match(/javascript/i)
25
+
26
+ response_params = request.filtered_parameters.dup
27
+ controller_name = response_params.delete('controller').to_s.underscore
28
+ action_name = response_params.delete('action').to_s
29
+
30
+ parsed_meta = self.class.response_metadata
31
+ parsed_meta = case parsed_meta
32
+ when Symbol then send(parsed_meta)
33
+ when Proc then parsed_meta.call
34
+ else parsed_meta
35
+ end
36
+
37
+ meta_info = {
38
+ :pathinfo => "#{controller_name}##{action_name}",
39
+ :meta => parsed_meta
40
+ }
41
+ response.header['X-Response-Meta'] = meta_info.to_json
42
+
43
+ end
44
+
45
+ module ClassMethods #:nodoc:
46
+
47
+ ##
48
+ # Adds additional "meta" information to AJAX response headers. By default an additional
49
+ # X-Response-Meta header is added to ajax requests which describes the current controller/action names. Passing
50
+ # additional information to this method adds data to that header.
51
+ #
52
+ # @param [Hash,Proc,Symbol] options Information to be added to the response header. If a hash is used, the data is passed
53
+ # directly. If a symbol is used, it is considered an instance method to be called on the controller. If a proc is used
54
+ # it is evaluated when the data is built. NOTE: Procs/methods are called AFTER actions are run. This way action data can be used.
55
+ #
56
+ # @example Add a "post_name" meta
57
+ #
58
+ # class PostsController < ApplicationController
59
+ # add_response_meta { :post_name => 'This post is awesome' }
60
+ # end
61
+ # * index action run *
62
+ #
63
+ # 'X-Response-Meta' #=> { :pathinfo => 'posts#index', :meta => { :post_name => 'This post is awesome' } }
64
+ #
65
+ #
66
+ def add_response_meta(options)
67
+ self.response_metadata = options
68
+ end
69
+
70
+ ##
71
+ # @deprecated Use add_response_meta
72
+ #
73
+ def enable_script_events(opts = {})
74
+ ActiveSupport::Deprecation.issue_warning("enable_script_events is deprecated. Please use the 'add_response_meta helper'")
75
+ response_metadata = opts
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
@@ -1,20 +1,19 @@
1
1
  require 'action_controller/base'
2
2
 
3
3
  module Motr
4
- module Controller
4
+ module Controller #:nodoc:
5
5
 
6
6
  ##
7
7
  #
8
8
  # A custom responder which extends the default functionality of respond_with to handle
9
9
  # more advanced javascript functionality, as well as flash messages.
10
10
  #
11
- # Slightly modeled after José Valim's Responders gem (https://github.com/plataformatec/responders)
11
+ # @see The ActionController::Metal::Responder (https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/responder.rb) for more info
12
12
  #
13
- # @see (https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/responder.rb) for more info
14
- #
15
- class Responder < ActionController::Responder
13
+ class Responder < ActionController::Responder #:nodoc:
16
14
 
17
- def initialize(controller, resources, options = {}) #:nodoc:
15
+ # @private
16
+ def initialize(controller, resources, options = {})
18
17
  super
19
18
  flash = (format == :js) ? controller.flash : controller.flash.now
20
19
  [:success, :notice, :error].each do |key|
@@ -24,8 +23,9 @@ module Motr
24
23
 
25
24
  ##
26
25
  # Override to_js to set a +X-Flash-Messages+ header to be utilized by an ajax response.
26
+ # @private
27
27
  #
28
- def to_js #:nodoc:
28
+ def to_js
29
29
  flash = controller.flash.now
30
30
  controller.response['X-Flash-Messages'] = flash.to_json if [:success, :notice, :error].detect{ |key| flash[key].present? }
31
31
  defined?(super) ? super : to_format
@@ -0,0 +1 @@
1
+ Motr.add_module(:sluggable, :autoload => true)
@@ -7,7 +7,7 @@ module Motr #:nodoc
7
7
  #
8
8
  #
9
9
  #
10
- class InvalidOptions < MotrError
10
+ class InvalidOptions < MotrError #:nodoc:
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,13 @@
1
+ module Motr #:nodoc
2
+ module Errors #:nodoc
3
+
4
+ ##
5
+ # Raised when trying to load a module that has not been added.
6
+ # @param (see Motr#Errors#MotrError)
7
+ #
8
+ #
9
+ #
10
+ class ModuleMissing < MotrError #:nodoc:
11
+ end
12
+ end
13
+ end
data/lib/motr/forms.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Motr
2
2
 
3
- module Forms
3
+ module Forms #:nodoc:
4
4
 
5
5
  autoload :Base, 'motr/forms/base'
6
6
  autoload :Helpers, 'motr/forms/helpers'
@@ -5,7 +5,7 @@ module Motr
5
5
  ##
6
6
  # Base class for creating form builders
7
7
  #
8
- class Base < ActionView::Helpers::FormBuilder
8
+ class Base < ActionView::Helpers::FormBuilder #:nodoc:
9
9
 
10
10
  # Access the template object
11
11
  attr_accessor :template
@@ -17,6 +17,7 @@ module Motr
17
17
 
18
18
 
19
19
  # Overrides fields_for to make sure the form builder is set properly
20
+ #
20
21
  def fields_for(record_or_name_or_array, *args, &block) #:nodoc:
21
22
  opts = args.extract_options!
22
23
  opts[:builder] ||= Motr::Forms.default_builder
@@ -205,7 +206,7 @@ module Motr
205
206
 
206
207
  private
207
208
 
208
- def validator_of_type_exists?(validators, kind, check_options = true) #:nodoc:
209
+ def validator_of_type_exists?(validators, kind, check_options = true) #:nodoc: @private
209
210
  validators.detect do |validator|
210
211
  exists = (validator.kind.to_s == kind.to_s)
211
212
  next exists unless (check_options && exists) && validator.options.present?
@@ -6,10 +6,10 @@ module Motr
6
6
  # Default Motr form builder. Extends the passed input tags to include additional
7
7
  # html attributes, primarily for javascript integration.
8
8
  #
9
- class Builder < Motr::Forms::Base
9
+ class Builder < Motr::Forms::Base #:nodoc:
10
10
 
11
11
  # create overrides for custom rendering
12
- [:email_field, :password_field, :text_field, :text_area, :url_field, ].each do |method|
12
+ [:email_field, :password_field, :text_field, :text_area, :url_field].each do |method|
13
13
  class_eval <<-FUNC, __FILE__, __LINE__ + 1
14
14
 
15
15
  alias :_super_#{method} :#{method}
@@ -21,9 +21,10 @@ module Motr
21
21
  end
22
22
 
23
23
  ##
24
- # Modified label tag to support adding a 'required' asterisk to the end of the label
24
+ # Modified label tag to support adding a 'required' asterisk to the end of the label.
25
+ # Same params as the original implementation
25
26
  #
26
- def label(method, text = nil, options = {}, &block)
27
+ def label(method, text = nil, options = {}, &block) #:nodoc:
27
28
 
28
29
  options, text = text, nil if text.is_a?(Hash)
29
30
  text ||= method.to_s.humanize
@@ -72,6 +72,7 @@ module Motr
72
72
 
73
73
  private
74
74
 
75
+ # @private
75
76
  def update_link_attrs(path, attrs)
76
77
 
77
78
  proc = attrs.delete(:proc)
data/lib/motr/model.rb ADDED
@@ -0,0 +1,124 @@
1
+ module Motr
2
+
3
+ ##
4
+ # Provides a interface for extending models and controllers with additional Motr libraries.
5
+ # To create a new library, sub-class/module Motr::Model or Motr::Controller depending on the
6
+ # functionality to include. To 'attach' functionality call motr :module_name
7
+ #
8
+ # @example Create a "postable" model using Motr::Model::Postable (see the motr-content gem)
9
+ # class MyPost
10
+ # motr :postable
11
+ # end
12
+ #
13
+ module Model
14
+ ##
15
+ # Stores a list of available options for a model. This way when
16
+ # options are passed at load-time, they can be applied to the proper modules.
17
+ #
18
+ # @param [Class, Module] mod The module to configure
19
+ # @param [Symbol] cfg_name The name of the configuration to modify
20
+ # @param [Array] *options Argument list of options to create.
21
+ #
22
+ # @example Create configuration options on a module
23
+ # module Motr::Model::Sample
24
+ # module ClassMethods
25
+ # Motr::Model.config(self, :sample, :option1, :option2)
26
+ # end
27
+ # end
28
+ #
29
+ #
30
+ def self.config(mod, cfg_name, *options)
31
+ (class << mod; self; end).send(:attr_accessor_with_default, :motr_options, {})
32
+ mod.motr_options[cfg_name] ||= []
33
+
34
+ options.each do |option|
35
+ mod.motr_options[cfg_name] << option
36
+ fullname = [cfg_name, option].map(&:to_s).join("_")
37
+
38
+ mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
39
+ def #{fullname}
40
+ if defined?(@#{fullname})
41
+ @#{fullname}
42
+ elsif superclass.respond_to?(:#{fullname})
43
+ superclass.#{fullname}
44
+ else
45
+ Motr::CONFIGS[:#{cfg_name}][:#{option}]
46
+ end
47
+ end
48
+ def #{fullname}=(value)
49
+ @#{fullname} = value
50
+ end
51
+ METHOD
52
+ end
53
+ end
54
+
55
+ ##
56
+ # The motr method enables loading other motr libraries into application modules/classes.
57
+ #
58
+ # @example Create a model include to hook into any model class
59
+ # module Motr::Model::Sample
60
+ # def instance_method
61
+ # end
62
+ #
63
+ # module ClassMethods
64
+ # def class_method
65
+ # end
66
+ # end
67
+ # end
68
+ #
69
+ # class SomeModel < ActiveRecord::Base
70
+ # motr :sample
71
+ # end
72
+ #
73
+ #
74
+ def motr(*mods)
75
+
76
+ options = mods.extract_options!
77
+ modules = mods.map(&:to_sym).uniq
78
+
79
+ motrize_model! do
80
+
81
+ modules.each do |mod|
82
+ const_name = mod.to_s.classify
83
+ raise Motr::Model.load_failure("Motr::Model::#{const_name}") unless Motr::ALL.include?(mod)
84
+
85
+ begin
86
+ const_incl = Motr::Model.const_get(:"#{const_name}")
87
+ rescue NameError
88
+ raise Motr::Errors.ModuleMissing.new("Motr::Model::#{const_name} could not be found. Perhaps try adding the module with the :autoload option.")
89
+ end
90
+
91
+ if const_incl.const_defined?('ClassMethods')
92
+ class_incl = const_incl.const_get("ClassMethods")
93
+ extend class_incl
94
+ end
95
+ # # Apply passed options to modules where applicable.
96
+ #
97
+ if class_incl.respond_to?(:motr_options)
98
+ class_incl.motr_options[mod].each do |option|
99
+ next unless options.key?(option)
100
+ send(:"#{mod}_#{option}=", options.delete(option))
101
+ end
102
+ end
103
+
104
+ include const_incl
105
+
106
+ end
107
+ end
108
+ end
109
+
110
+ # Raise a ModuleMissing error if a module cannot be loaded.
111
+ # @private
112
+ #
113
+ def self.load_failure(mod) #:nodoc:
114
+ Motr::Errors::ModuleMissing.new("The module #{mod} wasn't found. Add it with Motr.add_module(#{mod})") and return
115
+ end
116
+
117
+ # Override motrize_model! to create specific functionality on a model
118
+ # @private
119
+ def motrize_model! #:nodoc:
120
+ yield
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,45 @@
1
+ module Motr
2
+ module Model
3
+
4
+ module Sluggable #:nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ callback_opt = (self.sluggable_on || "save")
9
+ send(:"before_#{callback_opt.to_s}", :make_sluggable_fields)
10
+ end
11
+
12
+ # @private
13
+ def make_sluggable_fields #:nodoc:
14
+ [self.class.sluggable_fields].flatten.each do |atr|
15
+ orig = self.send(:"#{atr}")
16
+ self.send(:"#{atr}=", orig.to_slug)
17
+ end
18
+ end
19
+
20
+ # @private
21
+ module ClassMethods #:nodoc:
22
+ Motr::Model.config(self, :sluggable, :fields, :on)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Original implementation by Ludo van den Boom's to_slug plugin
32
+ # @see to_slug (https://github.com/ludo/to_slug)
33
+ #
34
+ module ToSlug #:nodoc:
35
+ def to_slug
36
+ value = self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s
37
+ value.gsub!(/[']+/, '')
38
+ value.gsub!(/\W+/, ' ')
39
+ value.strip!
40
+ value.downcase!
41
+ value.gsub!(' ', '-')
42
+ value
43
+ end
44
+ end
45
+ String.send(:include, ToSlug)
@@ -0,0 +1,16 @@
1
+ module Motr
2
+ module Orm
3
+
4
+ module ActiveRecord #:nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ extend Motr::Model
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
15
+
16
+ ActiveRecord::Base.send :include, Motr::Orm::ActiveRecord
@@ -0,0 +1,13 @@
1
+ module Motr
2
+ module Orm
3
+
4
+ module Mongoid #:nodoc:
5
+ end
6
+
7
+ end
8
+ end
9
+
10
+ Mongoid::Document::ClassMethods.class_eval do
11
+ include Motr::Model
12
+ include Motr::Orm::Mongoid
13
+ end
data/lib/motr/rails.rb CHANGED
@@ -6,12 +6,19 @@ module Motr
6
6
  require 'active_support/i18n'
7
7
  I18n.load_path << File.expand_path('../../config/locales/en.yml', __FILE__)
8
8
 
9
- initializer :after_initialize do
10
- ActionView::Base.send :default_form_builder=, Motr::Forms.default_builder
11
- ApplicationController.class_eval do
9
+ initializer 'motr.initializer' do
10
+ ActiveSupport.on_load(:action_view) do
11
+ include Motr::Helpers::LayoutHelpers
12
+ include Motr::Helpers::Navigation
13
+ include Motr::Helpers::Elements
14
+ include Motr::Forms::Helpers
15
+ self.send :default_form_builder=, Motr::Forms.default_builder
16
+ end
17
+ ActiveSupport.on_load(:action_controller) do
18
+ include Motr::Controller::Helpers
12
19
  self.responder = Motr::Controller::Responder
13
20
  end
14
- ActionController::Base.extend Motr::Controller::ScriptEvents
21
+
15
22
  end
16
23
 
17
24
  end
data/lib/motr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Motr #:nodoc:
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: motr
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brent Kirby
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-04 00:00:00 -04:00
13
+ date: 2011-05-09 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -123,9 +123,11 @@ files:
123
123
  - lib/generator/templates/compass/screen.scss
124
124
  - lib/generator/templates/motr.rb
125
125
  - lib/generator/templates/post_install
126
+ - lib/motr/controller/helpers.rb
126
127
  - lib/motr/controller/responder.rb
127
- - lib/motr/controller/script_events.rb
128
+ - lib/motr/defaults.rb
128
129
  - lib/motr/errors/invalid_options.rb
130
+ - lib/motr/errors/module_missing.rb
129
131
  - lib/motr/errors/motr_error.rb
130
132
  - lib/motr/forms/base.rb
131
133
  - lib/motr/forms/builder.rb
@@ -134,6 +136,10 @@ files:
134
136
  - lib/motr/helpers/elements.rb
135
137
  - lib/motr/helpers/layout_helpers.rb
136
138
  - lib/motr/helpers/navigation.rb
139
+ - lib/motr/model/sluggable.rb
140
+ - lib/motr/model.rb
141
+ - lib/motr/orm/active_record.rb
142
+ - lib/motr/orm/mongoid.rb
137
143
  - lib/motr/rails.rb
138
144
  - lib/motr/version.rb
139
145
  - lib/motr.rb
@@ -156,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
162
  requirements:
157
163
  - - ">="
158
164
  - !ruby/object:Gem::Version
159
- hash: 2716753183944900755
165
+ hash: 2672633965524668472
160
166
  segments:
161
167
  - 0
162
168
  version: "0"
@@ -1,77 +0,0 @@
1
- require 'action_controller/base'
2
-
3
- module Motr
4
- module Controller
5
-
6
- ##
7
- # Enables triggering javascript events from controllers. This helps with extraction of javascript from
8
- # actual view templates. Since by default Rails' respond_with will render a html template on a js request
9
- # where there is no .js.erb template, we can capture that content and trigger a javascript event with it.
10
- #
11
- # @option options [Symbol] :type The type of callback to use (only supports :jquery right now)
12
- #
13
- # @example
14
- # In your controller:
15
- # controller SomeResourceController < ApplicationController
16
- # respond_to :html, :js
17
- # enable_script_events :only => :create
18
- #
19
- # def create
20
- # # some create functionality here
21
- # # @some_resource.name = "Test"
22
- # respond_with(@some_resource)
23
- # end
24
- #
25
- # end
26
- #
27
- # With the view "create.html.erb"
28
- #
29
- # <div id="resource"><%= @some_resource.name %></div>
30
- #
31
- # Will return (where the last param is an object notation of any params passed (after filtering))
32
- #
33
- # jQuery.trigger("some_resource:create", "<div id=\"resource\">Test</div>", {});
34
- #
35
- #
36
- module ScriptEvents
37
-
38
- def enable_script_events(options = {}) #:nodoc:
39
-
40
-
41
- after_filter(options) do
42
-
43
- # TODO: Possibly support other js libraries? I mean... does anyone care? I don't
44
- #event_type = options.delete(:type) || :jquery
45
- event_type = :jquery
46
- callback_str = case event_type.to_s
47
- when 'prototype' then "alert('sorry, no prototype love');"
48
- else "jQuery.event.trigger('%s:%s', [%s, %s]);"
49
- end
50
-
51
- return true unless response.content_type.to_s.match(/javascript/i)
52
- response_params = request.filtered_parameters.dup
53
-
54
- cname = response_params.delete('controller').to_s.underscore
55
- aname = response_params.delete('action').to_s
56
- escape_map = {
57
- '\\' => '\\\\',
58
- '</' => '<\/',
59
- "\r\n" => '\n',
60
- "\n" => '\n',
61
- "\r" => '\n',
62
- '"' => '\\"',
63
- "'" => "\\'" }
64
-
65
- response_params.delete("format")
66
- json_params = response_params.to_json#.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { escape_map[$1] }
67
- old_body = response.body.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { escape_map[$1] }
68
- response.body = callback_str % [cname, aname, old_body.inspect, json_params.html_safe]
69
-
70
- end
71
-
72
- end
73
-
74
- end
75
-
76
- end
77
- end