lib/vedeu/borders/dsl.rb in vedeu-0.8.0 vs lib/vedeu/borders/dsl.rb in vedeu-0.8.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Vedeu module Borders # Provides a mechanism to help configure borders in Vedeu. @@ -9,18 +11,26 @@ include Vedeu::DSL include Vedeu::DSL::Border include Vedeu::DSL::Presentation include Vedeu::DSL::Use - # Set the character to be used to draw the bottom left corner of - # the border. - # - # Vedeu.border :border_demo do - # bottom_left '+' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/border.md} + # @param name [String|Symbol] The name of the interface or view + # to which this border belongs. + # @param block [Proc] + # @macro raise_requires_block + # @raise [Vedeu::Error::MissingRequired] When the name is not + # given. + # @return [Vedeu::Borders::Border] + def self.border(name, &block) + fail Vedeu::Error::MissingRequired unless name + fail Vedeu::Error::RequiresBlock unless block_given? + + Vedeu::Borders::Border.build(enabled: true, name: name, &block).store + end + + # {include:file:docs/dsl/by_method/bottom_left.md} # @param char [String] Character to be used as the bottom left # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -29,18 +39,11 @@ def bottom_left(char, options = {}) model.bottom_left = Vedeu::Cells::BottomLeft.new(attrs(char, options)) end alias_method :bottom_left=, :bottom_left - # Set the character to be used to draw the bottom right corner - # of the border. - # - # Vedeu.border :border_demo do - # bottom_right '+' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/bottom_right.md} # @param char [String] Character to be used as the bottom right # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -49,17 +52,11 @@ def bottom_right(char, options = {}) model.bottom_right = Vedeu::Cells::BottomRight.new(attrs(char, options)) end alias_method :bottom_right=, :bottom_right - # Disable the border: - # - # Vedeu.border :border_demo do - # disable! - # # ... some other code (will be ignored) - # end - # + # {include:file:docs/dsl/by_method/disable.md} # @return [Boolean] def disable! model.enabled = false hide_bottom! @@ -67,20 +64,13 @@ hide_right! hide_top! model.enabled end + alias_method :disabled!, :disable! - # Enable the border: - # (Borders are enabled by default when defined for an - # interface). - # - # Vedeu.border :border_demo do - # enable! - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/enable.md} # @return [Boolean] def enable! model.enabled = true show_bottom! @@ -88,19 +78,13 @@ show_right! show_top! model.enabled end + alias_method :enabled!, :enable! - # Set the character to be used to draw the top horizontal part - # of the border. - # - # Vedeu.border :border_demo do - # top_horizontal '-' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/top_horizontal.md} # @param char [String] Character to be used as the top # horizontal border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -110,18 +94,11 @@ model.top_horizontal = Vedeu::Cells::TopHorizontal .new(attrs(char, options)) end alias_method :top_horizontal=, :top_horizontal - # Set the character to be used to draw the bottom horizontal - # part of the border. - # - # Vedeu.border :border_demo do - # bottom_horizontal '-' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/bottom_horizontal.md} # @param char [String] Character to be used as the bottom # horizontal border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -131,18 +108,11 @@ model.bottom_horizontal = Vedeu::Cells::BottomHorizontal .new(attrs(char, options)) end alias_method :bottom_horizontal=, :bottom_horizontal - # Set the character to be used to draw a horizontal part of the - # border. - # - # Vedeu.border :border_demo do - # horizontal '-' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/horizontal.md} # @param char [String] Character to be used as the horizontal # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -151,20 +121,11 @@ def horizontal(char, options = {}) model.horizontal = Vedeu::Cells::Horizontal.new(attrs(char, options)) end alias_method :horizontal=, :horizontal - # Enable/disable the bottom border. - # - # Vedeu.border :border_demo do - # bottom true # or... - # bottom false # or... - # hide_bottom! # or... - # show_bottom! - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/bottom.md} # @param value [Boolean] All values evaluate as true except nil # and false. # @return [Boolean] def bottom(value) boolean = value ? true : false @@ -186,20 +147,11 @@ # @see Vedeu::Borders::DSL#bottom def show_bottom! bottom(true) end - # Enable/disable the left border. - # - # Vedeu.border :border_demo do - # left true # or... - # left false # or... - # hide_left! # or... - # show_left! - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/left.md} # @param value [Boolean] All values evaluate as true except nil # and false. # @return [Boolean] def left(value) boolean = value ? true : false @@ -221,20 +173,11 @@ # @see Vedeu::Borders::DSL#left def show_left! left(true) end - # Enable/disable the right border. - # - # Vedeu.border :border_demo do - # right true # or... - # right false # or... - # hide_right! # or... - # show_right! - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/right.md} # @param value [Boolean] All values evaluate as true except nil # and false. # @return [Boolean] def right(value) boolean = value ? true : false @@ -256,60 +199,29 @@ # @see Vedeu::Borders::DSL#right def show_right! right(true) end - # If you have you are showing a top border, you could add a - # title. - # - # Vedeu.border :border_demo do - # title 'My Cool Title' - # # ... some code - # end - # - # produces, depending on other customisations: - # - # +- My Cool Title --------------------------------+ - # + # {include:file:docs/dsl/by_method/title.md} # @param value [String] The title. # @return [String] def title(value) model.title = value model.title end alias_method :title=, :title - # If you have you are showing a bottom border, you could add a - # caption. - # - # Vedeu.border :border_demo do - # caption 'My Cool Caption' - # # ... some code - # end - # - # produces, depending on other customisations: - # - # +------------------------------ My Cool Caption -+ - # + # {include:file:docs/dsl/by_method/caption.md} # @param value [String] The caption. # @return [String] def caption(value) model.caption = value model.caption end alias_method :caption=, :caption - # Enable/disable the top border. - # - # Vedeu.border :border_demo do - # top true # or... - # top false # or... - # hide_top! # or... - # show_top! - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/top.md} # @param value [Boolean] All values evaluate as true except nil # and false. # @return [Boolean] def top(value) boolean = value ? true : false @@ -331,18 +243,11 @@ # @see Vedeu::Borders::DSL#top def show_top! top(true) end - # Set the character to be used to draw the top left corner of - # the border. - # - # Vedeu.border :border_demo do - # top_left '+' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/top_left.md} # @param char [String] Character to be used as the top left # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -351,18 +256,11 @@ def top_left(char, options = {}) model.top_left = Vedeu::Cells::TopLeft.new(attrs(char, options)) end alias_method :top_left=, :top_left - # Set the character to be used to draw the top right corner of - # the border. - # - # Vedeu.border :border_demo do - # top_right '+' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/top_right.md} # @param char [String] Character to be used as the top right # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -371,18 +269,11 @@ def top_right(char, options = {}) model.top_right = Vedeu::Cells::TopRight.new(attrs(char, options)) end alias_method :top_right=, :top_right - # Set the character to be used to draw the left vertical part of - # the border. - # - # Vedeu.border :border_demo do - # left_vertical '|' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/left_vertical.md} # @param char [String] Character to be used as the left vertical # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -392,18 +283,11 @@ model.left_vertical = Vedeu::Cells::LeftVertical .new(attrs(char, options)) end alias_method :left_vertical=, :left_vertical - # Set the character to be used to draw the right vertical part - # of the border. - # - # Vedeu.border :border_demo do - # right_vertical '|' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/right_vertical.md} # @param char [String] Character to be used as the right # vertical border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>] @@ -413,17 +297,10 @@ model.right_vertical = Vedeu::Cells::RightVertical .new(attrs(char, options)) end alias_method :right_vertical=, :right_vertical - # Set the character to be used to draw a vertical part of the - # border. - # - # Vedeu.border :border_demo do - # vertical '|' - # # ... some code - # end - # + # {include:file:docs/dsl/by_method/vertical.md} # @param char [String] Character to be used as the vertical # border character. # @param options [Hash<Symbol => Hash<Symbol => String>|String| # Symbol] # @option options colour [Hash<Symbol => String>]