lib/rough_swal.rb in rough_swal-0.0.2 vs lib/rough_swal.rb in rough_swal-0.0.3
- old
+ new
@@ -1,7 +1,7 @@
module RoughSwal
- PARAMETERS = [
+ SWAL_PARAMETERS = [
:title,
:text,
:type,
:allow_escape_key,
:custom_class,
@@ -23,17 +23,12 @@
:input_value,
:function,
]
- def self.configure(&block)
- Configure.(&block) if block_given?
- end
-
-
module ParamsSetter
- RoughSwal::PARAMETERS.each do |name|
+ RoughSwal::SWAL_PARAMETERS.each do |name|
class_eval <<-EOS
def #{name}(value)
@swal_params['#{name}'] = value
end
EOS
@@ -88,44 +83,47 @@
class Default
include ParamsSetter
+ class << self
+ def call(&block)
+ @default = new
+ @default.instance_eval(&block)
+ end
- def self.call(&block)
- @default = new
- @default.instance_eval(&block)
- end
-
- def self.params
- @default ? @default.params : {}
+ def params
+ @default ? @default.params : {}
+ end
end
def initialize
@swal_params = {}
end
def params
- @swal_params || {}
+ @swal_params
end
end
class Preset
- def self.call(name, &block)
- @preset ||= {}
- @preset[name] = Default.new.tap do |preset|
- preset.instance_eval(&block)
+ class << self
+ def call(name, &block)
+ @preset ||= {}
+ @preset[name] = Default.new.tap do |preset|
+ preset.instance_eval(&block)
+ end
end
- end
- def self.find(name)
- @preset[name].try(:params) || (raise NotFound)
+ def find(name)
+ @preset[name].try(:params) || (raise NotFound)
+ end
end
class NotFound < StandardError
@@ -170,9 +168,14 @@
def tag(js)
"<script>#{js}</script>"
end
+ end
+
+
+ def self.configure(&block)
+ Configure.(&block) if block_given?
end
self.configure do
preset(:success) { type :success }
\ No newline at end of file