Class: Moonrope::DSL::BaseDSL
- Inherits:
-
Object
- Object
- Moonrope::DSL::BaseDSL
- Defined in:
- lib/moonrope/dsl/base_dsl.rb
Instance Method Summary collapse
-
#authenticator(name, &block) ⇒ Object
Define a new authenticator.
-
#controller(name) { ... } ⇒ Object
Define a new controller or append values to an existing controller if it has already been defined.
-
#helper(name, options = {}) { ... } ⇒ Object
Define a new helper in the global namespace.
-
#initialize(base) ⇒ BaseDSL
constructor
Initiaize a new BaseDSL.
-
#shared_action(name, &block) ⇒ Object
Define a new global shared action.
-
#structure(name) { ... } ⇒ Object
Define a new structure.
Constructor Details
#initialize(base) ⇒ BaseDSL
Initiaize a new BaseDSL
14 15 16 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 14 def initialize(base) @base = base end |
Instance Method Details
#authenticator(name, &block) ⇒ Object
Define a new authenticator
73 74 75 76 77 78 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 73 def authenticator(name, &block) authenticator = Moonrope::Authenticator.new(name) dsl = Moonrope::DSL::AuthenticatorDSL.new(authenticator) dsl.instance_eval(&block) if block_given? @base.authenticators[name] = authenticator end |
#controller(name) { ... } ⇒ Object
Define a new controller or append values to an existing controller if it has already been defined.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 42 def controller(name, &block) existing = @base.controllers.select { |a| a.name == name }.first if existing controller = existing else controller = Moonrope::Controller.new(@base, name) @base.controllers << controller end controller.dsl.instance_eval(&block) if block_given? controller end |
#helper(name, options = {}) { ... } ⇒ Object
Define a new helper in the global namespace
60 61 62 63 64 65 66 67 68 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 60 def helper(name, = {}, &block) if @base.helper(name, nil) raise Moonrope::Errors::HelperAlreadyDefined, "Helper has already been defined with name `#{name}`" end helper_instance = Moonrope::Helper.new(name, nil, , &block) @base.helpers << helper_instance helper_instance end |
#shared_action(name, &block) ⇒ Object
Define a new global shared action
83 84 85 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 83 def shared_action(name, &block) @base.shared_actions[name] = block end |
#structure(name) { ... } ⇒ Object
Define a new structure
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moonrope/dsl/base_dsl.rb', line 24 def structure(name, &block) if existing = @base.structures.select { |s| s.name == name }.first structure = existing else structure = Moonrope::Structure.new(@base, name) @base.structures << structure end structure.dsl.instance_eval(&block) if block_given? structure end |