Class: Utopia::Link
- Inherits:
-
Object
- Object
- Utopia::Link
- Defined in:
- lib/utopia/link.rb
Constant Summary collapse
- XNODE_EXT =
".xnode"
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #eql?(other) ⇒ Boolean
- #external? ⇒ Boolean
- #href ⇒ Object
- #href? ⇒ Boolean
-
#initialize(kind, path, info = nil) ⇒ Link
constructor
A new instance of Link.
- #title ⇒ Object
- #to_href(options = {}) ⇒ Object
Constructor Details
#initialize(kind, path, info = nil) ⇒ Link
Returns a new instance of Link.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/utopia/link.rb', line 15 def initialize(kind, path, info = nil) path = Path.create(path) @kind = kind case @kind when :file @name = path.basename(XNODE_EXT) @path = path when :directory @name = path.dirname.basename(XNODE_EXT) @path = path when :virtual @name = path.to_s @path = nil end @components = @name.split(".") @locale = path.locale(XNODE_EXT) @title = components[0] if info @info = info.symbolize_keys else @info = {} end end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
49 50 51 |
# File 'lib/utopia/link.rb', line 49 def components @components end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
48 49 50 |
# File 'lib/utopia/link.rb', line 48 def info @info end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
44 45 46 |
# File 'lib/utopia/link.rb', line 44 def kind @kind end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
47 48 49 |
# File 'lib/utopia/link.rb', line 47 def locale @locale end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/utopia/link.rb', line 45 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
46 47 48 |
# File 'lib/utopia/link.rb', line 46 def path @path end |
Instance Method Details
#==(other) ⇒ Object
103 104 105 |
# File 'lib/utopia/link.rb', line 103 def == other return other && kind == other.kind && name == other.name && path == other.path end |
#[](key) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/utopia/link.rb', line 51 def [] (key) if key == :title return @title end return @info[key] end |
#eql?(other) ⇒ Boolean
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/utopia/link.rb', line 92 def eql? other if other && self.class == other.class return kind.eql?(other.kind) && name.eql?(other.name) && path.eql?(other.path) && info.eql?(other.info) else return false end end |
#external? ⇒ Boolean
77 78 79 |
# File 'lib/utopia/link.rb', line 77 def external? @info.key? :uri end |
#href ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/utopia/link.rb', line 59 def href if @info[:uri] return @info[:uri] elsif @path return @path.to_s else "\#" end end |
#href? ⇒ Boolean
69 70 71 |
# File 'lib/utopia/link.rb', line 69 def href? return href != "\#" end |
#title ⇒ Object
73 74 75 |
# File 'lib/utopia/link.rb', line 73 def title @info[:title] || @title.to_title end |
#to_href(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/utopia/link.rb', line 81 def to_href( = {}) [:content] ||= title [:class] ||= "link" if href == "\#" "<span class=#{[:class].dump}>#{[:content].to_html}</span>" else "<a class=#{[:class].dump} href=\"#{href.to_html}\">#{[:content].to_html}</a>" end end |