This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
213 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "spec" | ||
require "../../src/ext/uri" | ||
|
||
describe "URI Extensions" do | ||
describe "URI.join" do | ||
it "replaces the path part if only a path is given" do | ||
URI.join("http://foo.com/foo", "/bar").to_s.should eq("http://foo.com/bar") | ||
end | ||
|
||
it "replaces the full URI if the second URI is fully qualified" do | ||
URI.join("http://foo.com/foo", "http://bar.com/bar").to_s.should eq("http://bar.com/bar") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "habitat" | ||
require "./ext/*" | ||
require "./crankypants/migrator" | ||
|
||
module Crankypants | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
struct Nil | ||
def presence | ||
nil | ||
end | ||
end | ||
|
||
class String | ||
def presence | ||
blank? ? nil : self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
struct Time | ||
def to_iso8601 | ||
to_s("%FT%X%:z") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "uri" | ||
|
||
class URI | ||
def self.join(origin : URI | String, other : URI | String) | ||
origin = URI.parse(origin) unless origin.is_a?(URI) | ||
other = URI.parse(other) unless other.is_a?(URI) | ||
|
||
origin.dup.tap do |result| | ||
result.path = other.path | ||
|
||
if other.host | ||
result.scheme = other.scheme | ||
result.host = other.host | ||
result.port = other.port | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This directory contains various bits and pieces that are prime candidates | ||
for extraction into actual shards later on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Here's a little ATOM module that we could eventually extract | ||
# into a shard. Woohoo! | ||
module ATOM | ||
def self.build | ||
output = String::Builder.new | ||
xml = XML::Builder.new(output) | ||
xml.indent = 2 | ||
|
||
ATOM::FeedBuilder.new(xml).build do |feed| | ||
yield feed | ||
end | ||
|
||
output.to_s | ||
end | ||
|
||
|
||
module Shortcuts | ||
def field(name : String, value : String? = nil, **opts) | ||
@xml.element(name, **opts) do | ||
if value | ||
@xml.text value | ||
end | ||
end | ||
end | ||
|
||
def text_field(name : String, value : String, **opts) | ||
field name, value, **opts | ||
end | ||
end | ||
|
||
module CommonBuilderMethods | ||
include Shortcuts | ||
|
||
def id(id : String) | ||
text_field "id", id | ||
end | ||
|
||
def title(title : String) | ||
text_field "title", title | ||
end | ||
|
||
def link(url : String) | ||
return if url.nil? || url.blank? | ||
field "link", href: url, rel: "self" | ||
end | ||
|
||
def updated(t : Time) | ||
return if t.nil? | ||
text_field "updated", t.to_iso8601 | ||
end | ||
|
||
def author | ||
@xml.element "author" do | ||
yield PersonBuilder.new(@xml) | ||
end | ||
end | ||
end | ||
|
||
class FeedBuilder | ||
include CommonBuilderMethods | ||
|
||
def initialize(@xml : XML::Builder) | ||
end | ||
|
||
def build | ||
@xml.document do | ||
@xml.element "feed", xmlns: "http://www.w3.org/2005/Atom" do | ||
yield self | ||
end | ||
end | ||
end | ||
|
||
def entry | ||
@xml.element "entry" do | ||
yield EntryBuilder.new(@xml) | ||
end | ||
end | ||
end | ||
|
||
class EntryBuilder | ||
include CommonBuilderMethods | ||
|
||
def initialize(@xml : XML::Builder) | ||
end | ||
|
||
def content(html : String) | ||
field "content", html, type: "html" | ||
end | ||
end | ||
|
||
class PersonBuilder | ||
include Shortcuts | ||
|
||
def initialize(@xml : XML::Builder) | ||
end | ||
|
||
def name(name : String) | ||
text_field "name", name | ||
end | ||
|
||
def uri(uri : String) | ||
text_field "uri", uri | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters