sisyphus-rails 0.0.2 → 0.0.4

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.
data/README.md CHANGED
@@ -23,6 +23,7 @@ For a basic install include the following in your *app/assets/javascripts/applic
23
23
  To support IE6/7 users include jStorage as well
24
24
 
25
25
  //= require jstorage
26
+ //= require sisyphus
26
27
 
27
28
  ## How it Works
28
29
 
@@ -54,8 +55,7 @@ To stop Sisyphus from initializing on a form include the *with_sisyphus* option
54
55
  - Tests
55
56
  - Move away from form_tag_helper, should be able to do it all from form_helper? Script tag can go at the end anyhow. Why aren't we doing that right now? We don't seem to have access to the same variables that the regular form_for does. Also the options array gets muddied by the FormHelper form_for call -> it removes the [:html] section (we need the id of the form for sisyphus).
56
57
  - conflict resolution... i.e. you have an object edit form, the fields are populated from the DB but if you have local browser changes they may get overridden. We need a way to resolve conflicts between local and remote data -> could use a jquery based modal dialog to present the diff?
57
- - Model/Object based exclusions via config or activerecord extension?
58
- - Env. based and global on/off switches
58
+ - Model based exclusions via activerecord extension?
59
59
  - block based options (this would allow us to easily and neatly implement Sisyphus options)
60
60
 
61
61
  <%= form_for User.new do |f| %>
@@ -0,0 +1,14 @@
1
+ module Sisyphus
2
+ module Generators
3
+ class ConfigurationGenerator < ::Rails::Generators::Base
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc "Creates blank config file for extended configuration."
8
+
9
+ def create_yaml
10
+ template "sisyphus.yml", "config/sisyphus.yml"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ production:
2
+ # globally enable or disable sisyphus form protection
3
+ sisyphus_enabled: true
4
+ # models to exclude from the default enabled state
5
+ # note that lower case singular is used
6
+ # exclude_models: user,post
7
+ # models to include from the default disbaled state
8
+ # include_models: user,post
9
+
10
+ development:
11
+ sisyphus_enabled: true
12
+
13
+ test:
14
+ sisyphus_enabled: true
@@ -5,5 +5,10 @@ require "sisyphus-rails/form_tag_helper"
5
5
 
6
6
  module Sisyphus
7
7
  mattr_accessor :process
8
+ mattr_accessor :app_root
9
+ mattr_accessor :config
8
10
 
11
+ def self.setup
12
+ yield self
13
+ end
9
14
  end
@@ -1,4 +1,31 @@
1
1
  module Sisyphus
2
2
  class Engine < ::Rails::Engine
3
+
4
+ initializer "sisyphus-rails.load_config_data" do |app|
5
+ Sisyphus.setup do |config|
6
+ config.app_root = app.root
7
+
8
+ #Load the configuration from the environment or a yaml file
9
+ Sisyphus.config = Hash.new
10
+
11
+ #load the config file if we have it
12
+ if FileTest.exist?("#{::Rails.root}/config/sisyphus.yml")
13
+ config = YAML.load_file("#{::Rails.root}/config/sisyphus.yml")
14
+ config = config[::Rails.env]
15
+
16
+ Sisyphus.config["SISYPHUS_ENABLED"] = config['sisyphus_enabled'] if config.include?('sisyphus_enabled')
17
+ Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config.include?('exclude_models')
18
+ Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config.include?('include_models')
19
+
20
+ end
21
+
22
+ #if we have ENV flags prefer them
23
+ Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include?("SISYPHUS_ENABLED")
24
+ Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV.include?("EXCLUDE_MODELS")
25
+ Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV.include?("INCLUDE_MODELS")
26
+
27
+ end
28
+ end
29
+
3
30
  end
4
31
  end
@@ -2,13 +2,27 @@ module ActionView
2
2
  module Helpers
3
3
  module FormHelper
4
4
  def form_for_with_sisyphus(record, options = {}, &proc)
5
-
6
- if options[:with_sisyphus] == false
7
- Sisyphus::process = false
5
+
6
+ case record
7
+ when String, Symbol
8
+ object_name = record
8
9
  else
9
- Sisyphus::process = true
10
+ object = record.is_a?(Array) ? record.last : record
11
+ object_name = options[:as] || ActiveModel::Naming.param_key(object)
10
12
  end
11
13
 
14
+
15
+ # There is an order of precedence debugger
16
+ Sisyphus::process = true
17
+
18
+ Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config.include?("SISYPHUS_ENABLED")
19
+
20
+ if Sisyphus::config["EXCLUDE_MODELS"].present?
21
+ Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(object_name))
22
+ end
23
+
24
+ Sisyphus::process = options[:with_sisyphus] if options.include?(:with_sisyphus)
25
+
12
26
  #strip all the sisyphus options from the options hash before moving on
13
27
  form_for_without_sisyphus(record, options.reject{|k,v| k =~ /sisyphus(.*)/}, &proc)
14
28
  end
@@ -1,5 +1,5 @@
1
1
  module Sisyphus
2
2
  module Rails
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sisyphus-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -39,6 +39,8 @@ files:
39
39
  - LICENSE.txt
40
40
  - README.md
41
41
  - Rakefile
42
+ - lib/generators/sisyphus/configuration/configuration_generator.rb
43
+ - lib/generators/sisyphus/configuration/templates/sisyphus.yml
42
44
  - lib/sisyphus-rails.rb
43
45
  - lib/sisyphus-rails/engine.rb
44
46
  - lib/sisyphus-rails/form_helper.rb
@@ -61,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
63
  version: '0'
62
64
  segments:
63
65
  - 0
64
- hash: -93684305
66
+ hash: -690969235
65
67
  required_rubygems_version: !ruby/object:Gem::Requirement
66
68
  none: false
67
69
  requirements:
@@ -70,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  version: '0'
71
73
  segments:
72
74
  - 0
73
- hash: -93684305
75
+ hash: -690969235
74
76
  requirements:
75
77
  - requires jQuery 1.4+ to be included before Sisyphus
76
78
  - requires jQuery 1.8+ to be included if you require jStorage