Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
Improve efficiency/flexibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 30, 2017
1 parent 1ca5248 commit 063b99f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/trenni/uri.rb
Expand Up @@ -30,18 +30,22 @@ def initialize(base, fragment, query)
attr :fragment
attr :query

def to_str
buffer = [escape_path(@base)]
def append(buffer)
buffer << escape_path(@base)

if @query&.any?
buffer.push(query_separator, query_part)
buffer << query_separator << query_part
end

# It's not clear if this is correct. According to the spec, it should be percent encoded.
# CGI.escape(' ') -> '+' which is not correct according to the RFC.
buffer.push('#', escape(@fragment)) if @fragment
if @fragment
buffer << '#' << escape(@fragment)
end

return buffer.join
return buffer
end

def to_str
append(String.new)
end

alias to_s to_str
Expand Down
6 changes: 6 additions & 0 deletions spec/trenni/uri_spec.rb
Expand Up @@ -46,4 +46,10 @@
expect(subject.to_s).to be == "I/%E2%9D%A4%EF%B8%8F/UNICODE?face=%F0%9F%98%80"
end
end

it "can be an attribute" do
tag = Trenni::Tag.closed('img', src: Trenni::URI('image.jpg', x: 10))

expect(tag.to_s).to be == '<img src="image.jpg?x=10"/>'
end
end

0 comments on commit 063b99f

Please sign in to comment.