Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reduce the `href_resolver` mess for now

  • Loading branch information...
commit 5c398196385d11c0d0de55c9e3fd52a2d6204e3b 1 parent 0dbe7e6
@mislav authored
Showing with 14 additions and 14 deletions.
  1. +2 −7 app.rb
  2. +12 −7 models.rb
View
9 app.rb
@@ -76,11 +76,6 @@ def rfc_path doc
url doc_id, false
end
- # used internally in the RFC HTML generation phase
- def href_resolver
- ->(xref) { rfc_path(xref) if xref =~ /^RFC\d+$/ }
- end
-
def home_path
url '/'
end
@@ -129,7 +124,7 @@ def page_title title = nil
end
get "/url/*" do
- rfc = RfcDocument.resolve_url(params[:splat].first, href_resolver) { not_found }
+ rfc = RfcDocument.resolve_url(params[:splat].first) { not_found }
target = url(rfc.id)
target << '#' << params[:hash] if params[:hash]
redirect target
@@ -141,6 +136,6 @@ def page_title title = nil
@rfc = RfcDocument.fetch(params[:doc_id]) { not_found }
redirect to(@rfc.id) unless request.path == "/#{@rfc.id}"
- @rfc.make_pretty href_resolver
+ @rfc.make_pretty
erb :show, auto_last_modified: @rfc.last_modified
end
View
19 models.rb
@@ -25,13 +25,13 @@ def fetch doc_id
entry ? wrap(entry) : yield
end
- def resolve_url url, href_resolver = nil
+ def resolve_url url
doc_id = File.basename(url).sub(/\.(html|xml|txt)$/, '')
if doc_id.start_with? 'draft-'
doc_id.sub!(/-\d+$/, '') # strip draft version
fetch(doc_id) {
doc = wrap(RfcEntry.new)
- doc.initialize_draft(doc_id, href_resolver) { yield }
+ doc.initialize_draft(doc_id) { yield }
}
else
fetch(doc_id) { yield }
@@ -43,9 +43,9 @@ def initialize entry
@entry = entry
end
- def initialize_draft doc_id, href_resolver
+ def initialize_draft doc_id
entry.document_id = doc_id
- saved = fetch_and_render href_resolver do |xml_doc, fetcher|
+ saved = fetch_and_render do |xml_doc, fetcher|
entry.title = fetcher.title
entry.keywords = xml_doc.keywords
entry.save
@@ -63,9 +63,9 @@ def pretty?
!entry.body.nil?
end
- def make_pretty href_resolver
+ def make_pretty
if needs_fetch?
- fetch_and_render href_resolver
+ fetch_and_render
entry.save
end
end
@@ -76,7 +76,7 @@ def needs_fetch?
entry.updated_at.to_time < RFC.last_modified
end
- def fetch_and_render href_resolver
+ def fetch_and_render
fetcher = RfcFetcher.new self.id
entry.xml_source = fetcher.xml_url
entry.fetcher_version = fetcher.version
@@ -89,6 +89,11 @@ def fetch_and_render href_resolver
yield doc, fetcher if block_given?
end
end
+
+ # used in the RFC HTML generation phase
+ def href_resolver
+ ->(xref) { "/#{xref}" if xref =~ /^RFC\d+$/ }
+ end
end
require 'dm-migrations'
Please sign in to comment.
Something went wrong with that request. Please try again.