Class: Middleman::Sitemap::Resource
- Inherits:
-
Object
- Object
- Middleman::Sitemap::Resource
show all
- Includes:
- Contracts, Extensions::Traversal
- Defined in:
- lib/middleman-core/sitemap/resource.rb,
lib/middleman-core/sitemap/extensions/proxies.rb
Overview
Constant Summary
collapse
- METADATA_HASH =
{ options: Maybe[Hash], locals: Maybe[Hash], page: Maybe[Hash] }.freeze
Constants included
from Contracts
Contracts::PATH_MATCHER
Instance Attribute Summary collapse
Instance Method Summary
collapse
#children, #directory_index?, #eponymous_directory?, #eponymous_directory_path, #parent, #siblings, #traversal_root
Methods included from Contracts
#Contract
Constructor Details
#initialize(store, path, source = nil) ⇒ Resource
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/middleman-core/sitemap/resource.rb', line 48
def initialize(store, path, source=nil)
@store = store
@app = @store.app
@path = path
@ignored = false
source = Pathname(source) if source && source.is_a?(String)
@file_descriptor = if source && source.is_a?(Pathname)
::Middleman::SourceFile.new(source.relative_path_from(@app.source_dir), source, @app.source_dir, Set.new([:source]), 0)
else
source
end
@destination_path = @path
@metadata = { options: {}, locals: {}, page: {} }
@page_data = nil
end
|
Instance Attribute Details
#destination_path ⇒ String
Also known as:
request_path
The output path in the build directory for this resource
22
23
24
|
# File 'lib/middleman-core/sitemap/resource.rb', line 22
def destination_path
@destination_path
end
|
#file_descriptor ⇒ Object
Returns the value of attribute file_descriptor.
27
28
29
|
# File 'lib/middleman-core/sitemap/resource.rb', line 27
def file_descriptor
@file_descriptor
end
|
#ignored ⇒ Object
Returns the value of attribute ignored.
41
42
43
|
# File 'lib/middleman-core/sitemap/resource.rb', line 41
def ignored
@ignored
end
|
Returns the value of attribute metadata.
39
40
41
|
# File 'lib/middleman-core/sitemap/resource.rb', line 39
def metadata
@metadata
end
|
The source path of this resource (relative to the source directory,
without template extensions)
18
19
20
|
# File 'lib/middleman-core/sitemap/resource.rb', line 18
def path
@path
end
|
Instance Method Details
100
101
102
103
104
105
106
107
108
|
# File 'lib/middleman-core/sitemap/resource.rb', line 100
def add_metadata(meta={}, reverse=false)
@page_data = nil
@metadata = if reverse
meta.deep_merge(@metadata)
else
@metadata.deep_merge(meta)
end
end
|
#Any
This method returns an undefined value.
Ignore a resource directly, without going through the whole
ignore filter stuff.
181
|
# File 'lib/middleman-core/sitemap/resource.rb', line 181
Contract Any
|
#binary? ⇒ Boolean
174
175
176
|
# File 'lib/middleman-core/sitemap/resource.rb', line 174
def binary?
!file_descriptor.nil? && (file_descriptor[:types].include?(:binary) || ::Middleman::Util.binary?(file_descriptor[:full_path].to_s))
end
|
#Bool ⇒ Boolean
Whether the Resource is ignored
75
|
# File 'lib/middleman-core/sitemap/resource.rb', line 75
Contract Bool
|
#content_type ⇒ Object
196
197
198
|
# File 'lib/middleman-core/sitemap/resource.rb', line 196
def content_type
options[:content_type] || ::Rack::Mime.mime_type(ext, nil)
end
|
#data ⇒ Object
113
114
115
|
# File 'lib/middleman-core/sitemap/resource.rb', line 113
def data
@page_data ||= ::Middleman::Util.recursively_enhance(metadata[:page])
end
|
#ext ⇒ Object
135
136
137
|
# File 'lib/middleman-core/sitemap/resource.rb', line 135
def ext
File.extname(path)
end
|
120
|
# File 'lib/middleman-core/sitemap/resource.rb', line 120
Contract Hash
|
#ignore! ⇒ Object
182
183
184
|
# File 'lib/middleman-core/sitemap/resource.rb', line 182
def ignore!
@ignored = true
end
|
#ignored? ⇒ Boolean
189
190
191
|
# File 'lib/middleman-core/sitemap/resource.rb', line 189
def ignored?
@ignored
end
|
#indifferent_access? ⇒ Hash
Data about this resource, populated from frontmatter or extensions.
|
# File 'lib/middleman-core/sitemap/resource.rb', line 112
|
#locals ⇒ Object
128
129
130
|
# File 'lib/middleman-core/sitemap/resource.rb', line 128
def locals
metadata[:locals]
end
|
The metadata for this resource
38
|
# File 'lib/middleman-core/sitemap/resource.rb', line 38
Contract METADATA_HASH
|
#options ⇒ Object
121
122
123
|
# File 'lib/middleman-core/sitemap/resource.rb', line 121
def options
metadata[:options]
end
|
#page_id ⇒ Object
89
90
91
|
# File 'lib/middleman-core/sitemap/resource.rb', line 89
def page_id
metadata[:page][:id] || destination_path
end
|
#proxy_to(_path) ⇒ Object
60
61
62
|
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 60
def proxy_to(_path)
throw 'Resource#proxy_to has been removed. Use ProxyResource class instead.'
end
|
#render(opts = {}, locs = {}) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/middleman-core/sitemap/resource.rb', line 142
def render(opts={}, locs={})
return ::Middleman::FileRenderer.new(@app, file_descriptor[:full_path].to_s).template_data_for_file unless template?
md = metadata
opts = md[:options].deep_merge(opts)
locs = md[:locals].deep_merge(locs)
locs[:current_path] ||= destination_path
opts[:layout] = false if !opts.key?(:layout) && !@app.config.extensions_with_layout.include?(ext)
renderer = ::Middleman::TemplateRenderer.new(@app, file_descriptor[:full_path].to_s)
renderer.render(locs, opts)
end
|
#source_file ⇒ Object
84
85
86
|
# File 'lib/middleman-core/sitemap/resource.rb', line 84
def source_file
file_descriptor && file_descriptor[:full_path].to_s
end
|
A path without the directory index - so foo/index.html becomes
just foo. Best for linking.
83
|
# File 'lib/middleman-core/sitemap/resource.rb', line 83
Contract String
|
#template? ⇒ Boolean
76
77
78
79
|
# File 'lib/middleman-core/sitemap/resource.rb', line 76
def template?
return false if file_descriptor.nil?
!::Tilt[file_descriptor[:full_path].to_s].nil?
end
|
#to_s ⇒ Object
Also known as:
inspect
200
201
202
|
# File 'lib/middleman-core/sitemap/resource.rb', line 200
def to_s
"#<#{self.class} path=#{@path}>"
end
|
#url ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/middleman-core/sitemap/resource.rb', line 161
def url
url_path = destination_path
if @app.config[:strip_index_file]
url_path = url_path.sub(/(^|\/)#{Regexp.escape(@app.config[:index_file])}$/,
@app.config[:trailing_slash] ? '/' : '')
end
File.join(@app.config[:http_prefix], url_path)
end
|