Skip to content

Commit

Permalink
Started with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Mar 17, 2014
1 parent c0c04a8 commit fecd5aa
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.greenbar
Gemfile.lock
coverage/
.yardoc/
doc/
3 changes: 3 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-
LICENSE.txt
lib/**/*.rb
54 changes: 54 additions & 0 deletions lib/lotus/presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
module Lotus
# Presenter pattern implementation
#
# @since 0.1.0
#
# @example
# require 'lotus/view'
#
# class Map
# attr_reader :locations
#
# def initialize(locations)
# @locations = locations
# end
#
# def location_names
# @locations.join(', ')
# end
# end
#
# class MapPresenter
# include Lotus::Presenter
#
# def count
# locations.count
# end
#
# def location_names
# super.upcase
# end
#
# def inspect_object
# @object.inspect
# end
# end
#
# map = Map.new(['Rome', 'Boston'])
# presenter = MapPresenter.new(map)
#
# # access a map method
# puts presenter.locations # => ['Rome', 'Boston']
#
# # access presenter concrete methods
# puts presenter.count # => 1
#
# # uses super to access original object implementation
# puts presenter.location_names # => 'ROME, BOSTON'
#
# # it has private access to the original object
# puts presenter.inspect_object # => #<Map:0x007fdeada0b2f0 @locations=["Rome", "Boston"]>
module Presenter
# Initialize the presenter
#
# @param object [Object] the object to present
#
# @since 0.1.0
def initialize(object)
@object = object
end
Expand Down
71 changes: 71 additions & 0 deletions lib/lotus/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,100 @@ def self.included(base)
views.add(base)
end

# Set the directory root where templates are located
#
# @param root [String] the root path
#
# @see Lotus::View.root
#
# @since 0.1.0
#
# @example
# require 'lotus/view'
#
# Lotus::View.root = '/path/to/templates'
def self.root=(root)
@root = Pathname.new(root) rescue nil
end

# Returns the directory root where templates are located.
# If not already set, it returns the current directory.
#
# @return [Pathname] the root path for templates
#
# @see Lotus::View.root=
#
# @since 0.1.0
#
# @example with already set value
# require 'lotus/view'
#
# Lotus::View.root = '/path/to/templates'
# Lotus::View.root # => #<Pathname:/path/to/templates>
#
# @example with missing set value
# require 'lotus/view'
#
# Lotus::View.root # => #<Pathname:.>
def self.root
@root ||= begin
self.root = '.'
@root
end
end

# Sets the default layout for all the registered views.
#
# @param layout [Symbol] the layout name
#
# @since 0.1.0
#
# @see Lotus::View::Dsl#layout
# @see Lotus::View.load!
#
# @example
# require 'lotus/view'
#
# Lotus::View.layout = :application
#
# class IndexView
# include Lotus::View
# end
#
# Lotus::View.load!
# IndexView.layout # => ApplicationLayout
def self.layout=(layout)
@layout = Rendering::LayoutFinder.find(layout)
end

# Returns the default layout to assign to the registered views.
# If not already set, it returns a <tt>Rendering::NullLayout</tt>.
#
# @return [Class,Rendering::NullLayout] depends if already set or not.
#
# @since 0.1.0
#
# @see Lotus::View.layout=
def self.layout
@layout ||= Rendering::NullLayout
end

# A set of registered views.
#
# @return [Set] all the registered views.
#
# @api private
# @since 0.1.0
def self.views
@views ||= Set.new
end

# A set of registered layouts.
#
# @return [Set] all the registered layout.
#
# @api private
# @since 0.1.0
def self.layouts
@layouts ||= Set.new
end
Expand Down
Loading

0 comments on commit fecd5aa

Please sign in to comment.