Generators and config files
This commit is contained in:
parent
9120943f1a
commit
7bc17ca3ec
@ -0,0 +1,14 @@
|
|||||||
|
module Sisyphus
|
||||||
|
module Generators
|
||||||
|
class ConfigurationGenerator < ::Rails::Generators::Base
|
||||||
|
|
||||||
|
source_root File.expand_path('../templates', __FILE__)
|
||||||
|
|
||||||
|
desc "Creates blank config file for extended configuration."
|
||||||
|
|
||||||
|
def create_yaml
|
||||||
|
template "sisyphus.yml", "config/sisyphus.yml"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
lib/generators/sisyphus/configuration/templates/sisyphus.yml
Normal file
13
lib/generators/sisyphus/configuration/templates/sisyphus.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
production:
|
||||||
|
# globally enable or disable sisyphus form protection
|
||||||
|
sisyphus_enabled: true
|
||||||
|
# models to exclude from the default enabled state
|
||||||
|
# exclude_models: User,Post
|
||||||
|
# models to include from the default disbaled state
|
||||||
|
# include_models: User,Post
|
||||||
|
|
||||||
|
development:
|
||||||
|
sisyphus_enabled: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
sisyphus_enabled: true
|
@ -5,5 +5,10 @@ require "sisyphus-rails/form_tag_helper"
|
|||||||
|
|
||||||
module Sisyphus
|
module Sisyphus
|
||||||
mattr_accessor :process
|
mattr_accessor :process
|
||||||
|
mattr_accessor :app_root
|
||||||
|
mattr_accessor :config
|
||||||
|
|
||||||
|
def self.setup
|
||||||
|
yield self
|
||||||
|
end
|
||||||
end
|
end
|
@ -1,4 +1,31 @@
|
|||||||
module Sisyphus
|
module Sisyphus
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
|
|
||||||
|
initializer "sisyphus-rails.load_config_data" do |app|
|
||||||
|
Sisyphus.setup do |config|
|
||||||
|
config.app_root = app.root
|
||||||
|
|
||||||
|
#Load the configuration from the environment or a yaml file
|
||||||
|
Sisyphus.config = Hash.new
|
||||||
|
|
||||||
|
#load the config file if we have it
|
||||||
|
if FileTest.exist?("#{::Rails.root}/config/sisyphus.yml")
|
||||||
|
config = YAML.load_file("#{::Rails.root}/config/sisyphus.yml")
|
||||||
|
config = config[::Rails.env]
|
||||||
|
|
||||||
|
Sisyphus.config["SISYPHUS_ENABLED"] = config['organization_id'] if config['sisyphus_enabled'].present?
|
||||||
|
Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config['exclude_models'].present?
|
||||||
|
Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config['include_models'].present?
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
#if we have ENV flags prefer them
|
||||||
|
Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include? "SISYPHUS_ENABLED"
|
||||||
|
Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV["EXCLUDE_MODELS"]
|
||||||
|
Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV["INCLUDE_MODELS"]
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -2,11 +2,18 @@ module ActionView
|
|||||||
module Helpers
|
module Helpers
|
||||||
module FormHelper
|
module FormHelper
|
||||||
def form_for_with_sisyphus(record, options = {}, &proc)
|
def form_for_with_sisyphus(record, options = {}, &proc)
|
||||||
|
|
||||||
if options[:with_sisyphus] == false
|
# There is an order of precedence debugger
|
||||||
|
Sisyphus::process = true
|
||||||
|
|
||||||
|
Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config["SISYPHUS_ENABLED"].present?
|
||||||
|
|
||||||
|
# if Sisyphus::config["EXCLUDE_MODELS"].present?
|
||||||
|
# Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(record))
|
||||||
|
# end
|
||||||
|
|
||||||
|
if options[:with_sisyphus] == false
|
||||||
Sisyphus::process = false
|
Sisyphus::process = false
|
||||||
else
|
|
||||||
Sisyphus::process = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#strip all the sisyphus options from the options hash before moving on
|
#strip all the sisyphus options from the options hash before moving on
|
||||||
|
@ -5,6 +5,8 @@ module ActionView
|
|||||||
def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block)
|
def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block)
|
||||||
buf = ActiveSupport::SafeBuffer.new
|
buf = ActiveSupport::SafeBuffer.new
|
||||||
|
|
||||||
|
buf.safe_concat(Sisyphus::config.to_s)
|
||||||
|
|
||||||
if options.has_key?(:id) && Sisyphus::process
|
if options.has_key?(:id) && Sisyphus::process
|
||||||
buf.safe_concat("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus({excludeFields: $('input[name=utf8], input[name=_method], input[name=authenticity_token]')});});</script>")
|
buf.safe_concat("<script type=\"text/javascript\">$(document).ready(function() {$('##{options[:id]}').sisyphus({excludeFields: $('input[name=utf8], input[name=_method], input[name=authenticity_token]')});});</script>")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user