Skip to content

Commit

Permalink
Manual formatting and ignore prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperTux88 committed Jul 25, 2022
1 parent a43be83 commit 31f8be3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/discovery/hcard.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Status: 200 OK
Content-Type: text/html; charset=utf-8
```

<!-- prettier-ignore-start -->
```html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Expand Down Expand Up @@ -131,6 +132,7 @@ OFxcL+/diwyswWkVbeaNCrrdfz8LTDQcWv8GA6olBOx7RlgVb7k3HonHaQjaI+xv
</body>
</html>
```
<!-- prettier-ignore-end -->

## Additional information and specifications

Expand Down
2 changes: 2 additions & 0 deletions docs/entities/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ title: Entities

The diaspora\* federation protocol currently knows the following entities:

<!-- prettier-ignore-start -->
{% for entity in site.entities %}
- [{{ entity.title }}]({{ site.baseurl }}{{ entity.url }})
{% endfor %}
<!-- prettier-ignore-end -->
2 changes: 2 additions & 0 deletions docs/federation/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ title: Value types and formats
This page describes which types are used for values of the [federation entities][entities], and in which format they
need to be.

<!-- prettier-ignore-start -->
- TOC
{:toc}
<!-- prettier-ignore-end -->

## diaspora\* ID

Expand Down
28 changes: 17 additions & 11 deletions lib/diaspora_federation/discovery/xrd_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,33 @@ def add_links_to(xml)
data[:properties] = properties unless properties.empty?
end

# prettier-ignore
private_class_method def self.parse_links_from_xml_doc(doc, data)
links = []
doc.xpath("xrd:XRD/xrd:Link", NS).each do |node|
link = {}
LINK_ATTRS.each do |attr|
link[attr] = node[attr.to_s] if node.key?(attr.to_s)
doc
.xpath("xrd:XRD/xrd:Link", NS)
.each do |node|
link = {}
# prettier-ignore-start
LINK_ATTRS.each do |attr|
link[attr] = node[attr.to_s] if node.key?(attr.to_s)
end
# prettier-ignore-end
links << link
end
links << link
end
data[:links] = links unless links.empty?
end

# symbolize link keys from JSON hash, but only convert known keys
# prettier-ignore
private_class_method def self.symbolize_keys_for_links(links)
# prettier-ignore-start
links&.map do |link|
{}.tap do |hash|
LINK_ATTRS.each do |attr|
hash[attr] = link[attr.to_s] if link.key?(attr.to_s)
end
end
LINK_ATTRS.filter_map { |attr|
[attr, link[attr.to_s]] if link.key?(attr.to_s)
}.to_h
end
# prettier-ignore-end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/diaspora_federation/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def to_h
# @see Nokogiri::XML::Node.to_xml
#
# @return [Nokogiri::XML::Element] root element containing properties as child elements
# prettier-ignore
def to_xml
doc = Nokogiri::XML::Document.new
Nokogiri::XML::Element.new(self.class.entity_name, doc).tap do |root_element|
Expand Down Expand Up @@ -313,10 +314,13 @@ def add_property_to_xml(doc, root_element, name, value)
end

# Create simple node, fill it with text and append to root
# prettier-ignore
def simple_node(doc, name, value)
# prettier-ignore-start
Nokogiri::XML::Element.new(name.to_s, doc).tap do |node|
node.content = value unless value.empty?
end
# prettier-ignore-end
end

# Generates a hash with entity properties which is put to the "entity_data"
Expand Down
7 changes: 6 additions & 1 deletion lib/diaspora_federation/validators/rules/public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ def error_key
end

# Determines if value is a valid public key
# prettier-ignore
def valid_value?(value)
!value.nil? && (
return false if value.nil?

# prettier-ignore-start
(
(value.strip.start_with?("-----BEGIN PUBLIC KEY-----") &&
value.strip.end_with?("-----END PUBLIC KEY-----")) ||
(value.strip.start_with?("-----BEGIN RSA PUBLIC KEY-----") &&
value.strip.end_with?("-----END RSA PUBLIC KEY-----"))
)
# prettier-ignore-end
end

# This rule has no params.
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/diaspora_federation/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ module DiasporaFederation
end

describe "#to_json" do
# prettier-ignore-start
let(:basic_props) do
{
test1: "123",
Expand All @@ -246,6 +247,7 @@ module DiasporaFederation
]
)
end
# prettier-ignore-end
let(:entity_class) { Entities::TestComplexEntity }

it "generates expected JSON data" do
Expand Down Expand Up @@ -448,13 +450,16 @@ def self.from_hash(_arg1, _arg2, _arg3)
multi: [Entities::OtherEntity.new(asdf: "asdf"), Entities::OtherEntity.new(asdf: "asdf")]
}
end

# prettier-ignore-start
let(:nested_hash) do
{
asdf: nested_data[:asdf],
test: nested_data[:test].to_h,
multi: nested_data[:multi].map(&:to_h)
}
end
# prettier-ignore-end

it "gets returned as Hash by #to_h" do
entity = Entities::TestNestedEntity.new(nested_data)
Expand Down

0 comments on commit 31f8be3

Please sign in to comment.