Class: Utopia::Link
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
- #default_locale ⇒ Object
- #eql?(other) ⇒ 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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/utopia/link.rb', line 16 def initialize(kind, path, info = nil) path = Path.create(path) @info = info ? info.symbolize_keys : {} @locale = @info.delete(:locale) || path.locale(XNODE_EXT) @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 = @info[:path] ? Path.create(@info[:path]) : nil end @components = @name.split(".") @title = components[0] end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
44 45 46 |
# File 'lib/utopia/link.rb', line 44 def components @components end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
43 44 45 |
# File 'lib/utopia/link.rb', line 43 def info @info end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
39 40 41 |
# File 'lib/utopia/link.rb', line 39 def kind @kind end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
42 43 44 |
# File 'lib/utopia/link.rb', line 42 def locale @locale end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/utopia/link.rb', line 40 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
41 42 43 |
# File 'lib/utopia/link.rb', line 41 def path @path end |
Instance Method Details
#==(other) ⇒ Object
94 95 96 |
# File 'lib/utopia/link.rb', line 94 def == other return other && kind == other.kind && name == other.name && path == other.path end |
#[](key) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/utopia/link.rb', line 46 def [] (key) if key == :title return @title end return @info[key] end |
#default_locale ⇒ Object
98 99 100 |
# File 'lib/utopia/link.rb', line 98 def default_locale @locale == '' end |
#eql?(other) ⇒ Boolean
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/utopia/link.rb', line 83 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 |
#href ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/utopia/link.rb', line 54 def href @info.fetch(:uri) do if @path @path.to_s else nil end end end |
#href? ⇒ Boolean
64 65 66 |
# File 'lib/utopia/link.rb', line 64 def href? return href != nil end |
#title ⇒ Object
68 69 70 |
# File 'lib/utopia/link.rb', line 68 def title @info[:title] || @title.to_title end |
#to_href(options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/utopia/link.rb', line 72 def to_href( = {}) [:content] ||= title [:class] ||= "link" if href? "<a class=#{[:class].dump} href=\"#{href.to_html}\">#{[:content].to_html}</a>" else "<span class=#{[:class].dump}>#{[:content].to_html}</span>" end end |