hearthside-mentionable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 723a8ed6c10216ddfd049ddba8f3ffaaf2b75a37726d78daf59ed57d12a96138
4
+ data.tar.gz: d2c45c68cb094a598c3b461e572115080a9ced58e0634ce5c59bf53e3a29dfa0
5
+ SHA512:
6
+ metadata.gz: 489b52eb930a4f4dbf6ef166252478fce4dac7eacc0c8c5fb2a35242fafbde29fb49a7e350fc422765cdd69b896f150f0df41b5eed122822a5b25caea8810c68
7
+ data.tar.gz: 5c4ff163408a71d4803eddc334ec62a0b230ced76c502c3bfea406ed1d889cab658d53fcbf9a89f7bc640e92fde6e1a33d5ca233c762db6d03ab742d0725bb99
data/LICENSE.md ADDED
@@ -0,0 +1,33 @@
1
+ Mentionable Copyright 2020 Caleb Hearth (“Licensor”)
2
+
3
+ Hippocratic License Version Number: 2.1.
4
+
5
+ Purpose. The purpose of this License is for the Licensor named above to permit the Licensee (as defined below) broad permission, if consistent with Human Rights Laws and Human Rights Principles (as each is defined below), to use and work with the Software (as defined below) within the full scope of Licensor’s copyright and patent rights, if any, in the Software, while ensuring attribution and protecting the Licensor from liability.
6
+
7
+ Permission and Conditions. The Licensor grants permission by this license (“License”), free of charge, to the extent of Licensor’s rights under applicable copyright and patent law, to any person or entity (the “Licensee”) obtaining a copy of this software and associated documentation files (the “Software”), to do everything with the Software that would otherwise infringe (i) the Licensor’s copyright in the Software or (ii) any patent claims to the Software that the Licensor can license or becomes able to license, subject to all of the following terms and conditions:
8
+
9
+ * Acceptance. This License is automatically offered to every person and entity subject to its terms and conditions. Licensee accepts this License and agrees to its terms and conditions by taking any action with the Software that, absent this License, would infringe any intellectual property right held by Licensor.
10
+
11
+ * Notice. Licensee must ensure that everyone who gets a copy of any part of this Software from Licensee, with or without changes, also receives the License and the above copyright notice (and if included by the Licensor, patent, trademark and attribution notice). Licensee must cause any modified versions of the Software to carry prominent notices stating that Licensee changed the Software. For clarity, although Licensee is free to create modifications of the Software and distribute only the modified portion created by Licensee with additional or different terms, the portion of the Software not modified must be distributed pursuant to this License. If anyone notifies Licensee in writing that Licensee has not complied with this Notice section, Licensee can keep this License by taking all practical steps to comply within 30 days after the notice. If Licensee does not do so, Licensee’s License (and all rights licensed hereunder) shall end immediately.
12
+
13
+ * Compliance with Human Rights Principles and Human Rights Laws.
14
+
15
+ 1. Human Rights Principles.
16
+
17
+ (a) Licensee is advised to consult the articles of the United Nations Universal Declaration of Human Rights and the United Nations Global Compact that define recognized principles of international human rights (the “Human Rights Principles”). Licensee shall use the Software in a manner consistent with Human Rights Principles.
18
+
19
+ (b) Unless the Licensor and Licensee agree otherwise, any dispute, controversy, or claim arising out of or relating to (i) Section 1(a) regarding Human Rights Principles, including the breach of Section 1(a), termination of this License for breach of the Human Rights Principles, or invalidity of Section 1(a) or (ii) a determination of whether any Law is consistent or in conflict with Human Rights Principles pursuant to Section 2, below, shall be settled by arbitration in accordance with the Hague Rules on Business and Human Rights Arbitration (the “Rules”); provided, however, that Licensee may elect not to participate in such arbitration, in which event this License (and all rights licensed hereunder) shall end immediately. The number of arbitrators shall be one unless the Rules require otherwise.
20
+
21
+ Unless both the Licensor and Licensee agree to the contrary: (1) All documents and information concerning the arbitration shall be public and may be disclosed by any party; (2) The repository referred to under Article 43 of the Rules shall make available to the public in a timely manner all documents concerning the arbitration which are communicated to it, including all submissions of the parties, all evidence admitted into the record of the proceedings, all transcripts or other recordings of hearings and all orders, decisions and awards of the arbitral tribunal, subject only to the arbitral tribunal's powers to take such measures as may be necessary to safeguard the integrity of the arbitral process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3) Article 26(6) of the Rules shall not apply.
22
+
23
+ 2. Human Rights Laws. The Software shall not be used by any person or entity for any systems, activities, or other uses that violate any Human Rights Laws. “Human Rights Laws” means any applicable laws, regulations, or rules (collectively, “Laws”) that protect human, civil, labor, privacy, political, environmental, security, economic, due process, or similar rights; provided, however, that such Laws are consistent and not in conflict with Human Rights Principles (a dispute over the consistency or a conflict between Laws and Human Rights Principles shall be determined by arbitration as stated above). Where the Human Rights Laws of more than one jurisdiction are applicable or in conflict with respect to the use of the Software, the Human Rights Laws that are most protective of the individuals or groups harmed shall apply.
24
+
25
+ 3. Indemnity. Licensee shall hold harmless and indemnify Licensor (and any other contributor) against all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including Licensor’s reasonable attorneys’ fees, arising out of or relating to Licensee’s use of the Software in violation of Human Rights Laws or Human Rights Principles.
26
+
27
+ * Failure to Comply. Any failure of Licensee to act according to the terms and conditions of this License is both a breach of the License and an infringement of the intellectual property rights of the Licensor (subject to exceptions under Laws, e.g., fair use). In the event of a breach or infringement, the terms and conditions of this License may be enforced by Licensor under the Laws of any jurisdiction to which Licensee is subject. Licensee also agrees that the Licensor may enforce the terms and conditions of this License against Licensee through specific performance (or similar remedy under Laws) to the extent permitted by Laws. For clarity, except in the event of a breach of this License, infringement, or as otherwise stated in this License, Licensor may not terminate this License with Licensee.
28
+
29
+ * Enforceability and Interpretation. If any term or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, then such invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction; provided, however, subject to a court modification pursuant to the immediately following sentence, if any term or provision of this License pertaining to Human Rights Laws or Human Rights Principles is deemed invalid, illegal, or unenforceable against Licensee by a court of competent jurisdiction, all rights in the Software granted to Licensee shall be deemed null and void as between Licensor and Licensee. Upon a determination that any term or provision is invalid, illegal, or unenforceable, to the extent permitted by Laws, the court may modify this License to affect the original purpose that the Software be used in compliance with Human Rights Principles and Human Rights Laws as closely as possible. The language in this License shall be interpreted as to its fair meaning and not strictly for or against any party.
30
+
31
+ * Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES “AS IS,” WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
32
+
33
+ This Hippocratic License is an Ethical Source license (https://ethicalsource.dev) and is offered for use by licensors and licensees at their own risk, on an “AS IS” basis, and with no warranties express or implied, to the maximum extent permitted by Laws.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Mentionable
2
+
3
+ An implementation of [Webmention], a web standard for mentions and conversyions
4
+ across the web. With mentionable, people can reply by sending webmentions for:
5
+
6
+ [Webmention]: <https://www.w3.org/TR/webmention/> "Webmention W3C Recommendation"
7
+
8
+ - commenting
9
+ - liking
10
+ - reposting
11
+ - mentioning / linking to
12
+ - quote
13
+
14
+ The `h-entry` specification provides for more types of reply, but these are what
15
+ Mentionable currently supports.
16
+
17
+ Mentionable sets up an endpoint in your Rails app to receive these Webmentions,
18
+ confirms that the reply actually links back to a page you've published, and
19
+ stores replies in the database for you to display or use as you please.
20
+
21
+ Optionally, Mentionable can be configured to send Webmentions when content you
22
+ create links to external sites. It does this by querying the link, performing
23
+ [Webmention endpoint discovery], and notifying sites that are set up to receive
24
+ Webmentions.
25
+
26
+ [Webmention endpoint discovery]: <https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint>
27
+
28
+ You can configure one or more objects to be queried upon creation by telling
29
+ Mentionable what they are and what method to check for links.
30
+
31
+ ## Usage
32
+ How to use my plugin.
33
+
34
+ ## Installation
35
+ Add this line to your application's Gemfile:
36
+
37
+ ```ruby
38
+ gem 'mentionable'
39
+ ```
40
+
41
+ And then execute:
42
+ ```bash
43
+ $ bundle
44
+ ```
45
+
46
+ Or install it yourself as:
47
+ ```bash
48
+ $ gem install mentionable
49
+ ```
50
+
51
+ ## Contributing
52
+ Contribution directions go here.
53
+
54
+ ## License
55
+
56
+ See LICENSE.md
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Mentionable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/mentionable .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module Mentionable
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require_dependency "mentionable/application_controller"
2
+
3
+ module Mentionable
4
+ class MentionsController < ApplicationController
5
+ skip_forgery_protection
6
+
7
+ def create
8
+ source = URI(params.fetch(:source) { missing_source_or_target; return })
9
+ target = URI(params.fetch(:target) { missing_source_or_target; return })
10
+
11
+ if source == target
12
+ render(
13
+ plain: "source URL cannot be the same as target URL",
14
+ status: :bad_request,
15
+ )
16
+ return
17
+ end
18
+
19
+ [source, target].each do |uri|
20
+ if !%w(http https).include? uri.scheme
21
+ render(
22
+ plain: "#{uri} is not a valid URL. Please use http:// or https://",
23
+ status: :bad_request,
24
+ )
25
+ return
26
+ end
27
+ end
28
+
29
+ Mentionable.config.request_verification_job.perform_later(source.to_s, target.to_s)
30
+
31
+ head :accepted
32
+ end
33
+
34
+ private
35
+
36
+ def missing_source_or_target
37
+ render(
38
+ plain: "source and target params are required and must be HTTP or HTTPS URLs",
39
+ status: :bad_request,
40
+ )
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ module Mentionable
2
+ module ApplicationHelper
3
+ def webmention_link_tag(href = mentionable.mentions_url)
4
+ tag("link", { rel: "webmention", href: href })
5
+ end
6
+
7
+ def add_webmention_header(href = mentionable.mentions_url)
8
+ response.set_header("Link", %(<#{href}>; rel="webmention"))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Mentionable
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,31 @@
1
+ require "net/http"
2
+
3
+ # Query a {Mention#source} to confirm that it mentions the {Mention#target}.
4
+ # If the source mentions the target, the {Mention#status} is updated to
5
+ # "verified", else it is updated to "failed".
6
+ #
7
+ # Defaults to caching the HTTP response on the {Mention}.
8
+ class Mentionable::ConfirmMentionJob < ApplicationJob
9
+ queue_as :default
10
+
11
+ # @param mention [Mention] Mention to confirm
12
+ # @param cache [Boolean] Cache the HTTP response on the {Mention}
13
+ # @todo Look for href/src/srcset attribute values, not bare mentions of URLs.
14
+ # Nokogiri?
15
+ # @todo Use per-media-type rules to determine whether the source document
16
+ # mentions the target URL.
17
+ # @see https://www.w3.org/TR/webmention/#webmention-verification-p-3
18
+ def perform(mention, cache: true)
19
+ source_page = Net::HTTP.get(URI(mention.source))
20
+ mentioned_urls = URI.extract(source_page, %w[http https])
21
+ if mentioned_urls.include?(mention.target)
22
+ mention.status = "verified"
23
+ else
24
+ mention.status = "failed"
25
+ end
26
+ if cache
27
+ mention.html = source_page
28
+ end
29
+ mention.save!
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module Mentionable
2
+ # Job to save a {Mention} with the provided source and target.
3
+ # After persisting, a {Mentionable::Configuration#webmention_verification_job} is enqueued.
4
+ class SaveMentionJob < ApplicationJob
5
+ queue_as :default
6
+
7
+ # @param source [String] source URL of the Webmention source
8
+ # @param target [String] target URL of the Webmention target
9
+ # @param valid [Boolean] whether the target URL was valid in
10
+ # {Mentionable::Configuration.verify_with_router_job
11
+ # Mentionable.config.verify_with_router_job}
12
+ # @raise [ActiveRecord::RecordInvalid] if the {Mention} would be invalid
13
+ # with the given source and target inputs.
14
+ def perform(source:, target:, valid:)
15
+ mention = Mentionable::Mention.create!({
16
+ source:,
17
+ target:,
18
+ status: valid ? :awaiting_verification : :target_not_recognized,
19
+ })
20
+ Mentionable.config.webmention_verification_job.perform_later(mention)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Mentionable
2
+ # Job to verify incoming webmentions that have passed the initial set of
3
+ # verifications (source and target both present, not identical, and are valid
4
+ # URLs).
5
+ #
6
+ # Verifies that the Rails router has a path that matches the target URL's
7
+ # path. Pass source, target, and validity to
8
+ # {Mentionable::Configuration#persistence_job
9
+ # Mentionable.config.persistence_job}.
10
+ class VerifyWithRouterJob < ApplicationJob
11
+ queue_as :default
12
+
13
+ def perform(source, target)
14
+ Mentionable.config.persistence_job
15
+ .perform_later(source:, target:, valid: valid_path(target))
16
+ end
17
+
18
+ private
19
+
20
+ def valid_path(target)
21
+ Rails.application.routes.recognize_path(target)
22
+ true
23
+ rescue ActionController::RoutingError
24
+ false
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Mentionable
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Mentionable
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Mentionable
2
+ class Mention < ApplicationRecord
3
+ validates :target,
4
+ presence: true,
5
+ comparison: { other_than: :source, if: :source }
6
+ validates :source, presence: true
7
+ enum :status, [
8
+ :target_not_recognized,
9
+ :awaiting_verification,
10
+ :verified,
11
+ :failed,
12
+ ].to_h { [_1, _1.to_s] }
13
+
14
+ def microformat_items
15
+ H.from_html(html)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mentionable</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "mentionable/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Mentionable::Engine.routes.draw do
2
+ post "/webmention", to: "mentions#create", as: :mentions
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreateMentionableMentions < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :mentionable_mentions do |t|
4
+ t.string :source, null: false
5
+ t.string :target, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class AddStatusAndHtmlAndMicroformatsToMentions < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :mentionable_mentions, :status, :string
4
+ add_column :mentionable_mentions, :html, :text
5
+ end
6
+ end
data/lib/h/adr.rb ADDED
@@ -0,0 +1,30 @@
1
+ class H::Adr
2
+ include ActiveModel::AttributeAssignment
3
+
4
+ attr_accessor :street_address
5
+ attr_accessor :extended_address
6
+ attr_accessor :post_office_box
7
+ attr_accessor :locality
8
+ attr_accessor :region
9
+ attr_accessor :postal_code
10
+ attr_accessor :country_name
11
+ attr_accessor :label
12
+ attr_accessor :geo
13
+ attr_accessor :latitude
14
+ attr_accessor :longitude
15
+ attr_accessor :altitude
16
+ attr_accessor :children
17
+
18
+ def initialize(properties: nil, children: nil)
19
+ if properties
20
+ # name will be ignored per https://microformats.org/wiki/h-adr#:~:text=there%20is%20no%20%22p%2Dname%22%20property%20in%20h%2Dadr
21
+ properties.delete(:name)
22
+ assign_attributes(properties.to_h { |k, v| [k.to_s.underscore.to_sym, v.first] })
23
+ end
24
+ @children = children&.flat_map { H.parse([_1]) }
25
+ end
26
+
27
+ def ==(other)
28
+ other.is_a?(self.class) && instance_values == other.instance_values
29
+ end
30
+ end
data/lib/h/base.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "microformats"
2
+
3
+ class H::Base
4
+ def self.plural_attributes = [] # :nodoc:
5
+ def self.date_attributes = [] # :nodoc:
6
+ def self.special_attributes = [] # :nodoc:
7
+
8
+ def self.from_html(html)
9
+ h = Microformats
10
+ .parse(html)
11
+ .items
12
+ .first
13
+ .to_hash
14
+ new(properties: h["properties"], children: h["children"])
15
+ end
16
+
17
+ def initialize(properties:, children: nil)
18
+ properties = properties&.with_indifferent_access
19
+ children = children&.map(&:with_indifferent_access)
20
+ singular_attributes = self.class.attributes -
21
+ self.class.plural_attributes -
22
+ self.class.date_attributes -
23
+ self.class.special_attributes
24
+
25
+ self.class.plural_attributes.each do |attribute|
26
+ if (items = properties[attribute.to_s.singularize.dasherize])
27
+ instance_variable_set("@#{attribute}", H.parse(items))
28
+ end
29
+ end
30
+ singular_attributes.each do |attribute|
31
+ if (item = properties[attribute.to_s.dasherize]&.first)
32
+ instance_variable_set("@#{attribute}", H.parse([item]).first)
33
+ end
34
+ end
35
+ self.class.date_attributes.each do |attribute|
36
+ if (date = properties[attribute]&.first)
37
+ instance_variable_set("@#{attribute}", DateTime.parse(date))
38
+ end
39
+ end
40
+ @children = children&.flat_map { H.parse([_1]) }
41
+ end
42
+
43
+ def inspect
44
+ attr_strings = self
45
+ .class
46
+ .attributes
47
+ .filter_map { (value = instance_variable_get("@#{_1}")) && " @#{_1}=#{value.inspect}" }
48
+ .join(",")
49
+ %[#<#{self.class.name}:#{object_id}#{attr_strings}>]
50
+ end
51
+
52
+ def ==(other)
53
+ other.is_a?(self.class) && instance_values == other.instance_values
54
+ end
55
+ end
data/lib/h/card.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "microformats"
2
+
3
+ class H::Card < H::Base
4
+ def self.attributes # :nodoc:
5
+ [
6
+ :name,
7
+ :honorific_prefix,
8
+ :given_name,
9
+ :additional_name,
10
+ :family_name,
11
+ :sort_string,
12
+ :honorific_suffix,
13
+ :nickname,
14
+ :emails,
15
+ :logo,
16
+ :photos,
17
+ :urls,
18
+ :uid,
19
+ :categories,
20
+ :adrs,
21
+ :post_office_box,
22
+ :extended_address,
23
+ :street_address,
24
+ :locality,
25
+ :region,
26
+ :postal_code,
27
+ :country_name,
28
+ :label,
29
+ :geo,
30
+ :latitude,
31
+ :longitude,
32
+ :altitude,
33
+ :tels,
34
+ :note,
35
+ :bday,
36
+ :key,
37
+ :orgs,
38
+ :job_title,
39
+ :role,
40
+ :impp,
41
+ :sex,
42
+ :gender_identity,
43
+ :anniversary,
44
+ :children,
45
+ ]
46
+ end
47
+
48
+ def self.plural_attributes = %i[emails photos urls categories adrs tels orgs]
49
+ def self.date_attributes = %i[bday anniversary]
50
+
51
+ attributes.each { attr_reader _1 }
52
+ end
data/lib/h/cite.rb ADDED
@@ -0,0 +1,10 @@
1
+ class H::Cite < H::Base
2
+ def self.attributes = %i[name published author url uid publication accessed content]
3
+ def self.date_attributes = %i[published accessed]
4
+
5
+ attr_accessor *attributes
6
+
7
+ def initialize(properties:, children: nil)
8
+ super
9
+ end
10
+ end
data/lib/h/entry.rb ADDED
@@ -0,0 +1,51 @@
1
+ class H::Entry < H::Base
2
+ def self.attributes # :nodoc:
3
+ [
4
+ :name,
5
+ :summary,
6
+ :content,
7
+ :published,
8
+ :updated,
9
+ :author,
10
+ :categories,
11
+ :url,
12
+ :uid,
13
+ :location,
14
+ :syndications,
15
+ :in_reply_to,
16
+ :rsvp,
17
+ :like_of,
18
+ :repost_of,
19
+ :comments,
20
+ :photos,
21
+ :videos,
22
+ :audios,
23
+ :likes,
24
+ :reposts,
25
+ :bookmark_of,
26
+ :featured,
27
+ :duration,
28
+ :size,
29
+ :listen_of,
30
+ :watch_of,
31
+ :read_of,
32
+ :translation_of,
33
+ :checkin,
34
+ :children,
35
+ ]
36
+ end
37
+
38
+ def self.plural_attributes
39
+ %i[categories syndications comments photos videos audios likes reposts in_reply_to]
40
+ end
41
+
42
+ def self.date_attributes = %i[published updated]
43
+ def self.special_attributes = %i[content]
44
+
45
+ attributes.each { attr_accessor _1 }
46
+
47
+ def initialize(properties:, children: nil)
48
+ super
49
+ @content = properties[:content]
50
+ end
51
+ end
data/lib/h.rb ADDED
@@ -0,0 +1,35 @@
1
+ module H
2
+ class << self
3
+ def from_html(html)
4
+ parse(Microformats.parse(html).to_h["items"])
5
+ end
6
+
7
+ def parse(items)
8
+ items.map do |item|
9
+ if item.is_a? String
10
+ item
11
+ else
12
+ item = item.to_hash.with_indifferent_access
13
+ case item[:type]&.first
14
+ when "h-adr"
15
+ H::Adr.new(properties: item[:properties], children: item[:children])
16
+ when "h-card"
17
+ H::Card.new(properties: item[:properties], children: item[:children])
18
+ when "h-cite"
19
+ H::Cite.new(properties: item[:properties], children: item[:children])
20
+ when "h-entry"
21
+ H::Entry.new(properties: item[:properties], children: item[:children])
22
+ else
23
+ item
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ require "h/base"
32
+ require "h/adr"
33
+ require "h/card"
34
+ require "h/cite"
35
+ require "h/entry"
@@ -0,0 +1,61 @@
1
+ module Mentionable
2
+ class Configuration
3
+ # The Mentionable request verification job to use when a new webmention is
4
+ # received. It is responsible for verifying the webmention per
5
+ # https://www.w3.org/TR/webmention/#request-verification and then enqueuing
6
+ # a {#persistence_job}.
7
+ #
8
+ # Defaults to {VerifyWithRouterJob}
9
+ # @return [Class] Mentionable request verification job
10
+ attr_accessor :request_verification_job
11
+
12
+ # The Mentionable persistence job is used when a source and target have been
13
+ # successfully verified to save the webmention. It should persist the
14
+ # webmention and then enqueue a {#webmention_verification_job} with the
15
+ # persisted record.
16
+ #
17
+ # Defaults to {SaveMentionJob}
18
+ # @return [Class] Mentionable persistence job
19
+ attr_accessor :persistence_job
20
+
21
+ # The Mentionable webmention verification job to use when a new webmention is
22
+ # received. It is responsible for verifying the webmention per
23
+ # https://www.w3.org/TR/webmention/#webmention-verification and optionally
24
+ # updating the {Mention} with a cache of the HTTP response and parsed
25
+ # microformat data.
26
+ #
27
+ # Defaults to {ConfirmMentionJob}
28
+ # @return [Class] Mentionable request verification job
29
+ attr_accessor :webmention_verification_job
30
+
31
+ def initialize
32
+ @request_verification_job = Mentionable::VerifyWithRouterJob
33
+ @persistence_job = Mentionable::SaveMentionJob
34
+ @webmention_verification_job = Mentionable::ConfirmMentionJob
35
+ end
36
+ end
37
+
38
+ # @return [Mentionable::Configuration] Mentionable's current config
39
+ def self.config
40
+ @config ||= Configuration.new
41
+ end
42
+
43
+ # Set Mentionable's config
44
+ #
45
+ # @param config [Mentionable::Configuration]
46
+ def self.config=(config)
47
+ @config = config
48
+ end
49
+
50
+ # Modify Mentionable's current config
51
+ #
52
+ # @yieldparam [Mentionable::Configuration] config current Mentionable config
53
+ # ```
54
+ # Mentionable.configure do |config|
55
+ # config.request_verification_job = Mentionable::VerifyWithRouterJob
56
+ # end
57
+ # ```
58
+ def self.configure
59
+ yield config
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module Mentionable
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Mentionable
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Mentionable
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ require "mentionable/engine"
2
+ require "mentionable/configuration"
3
+ require "h"
4
+
5
+ module Mentionable
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :mentionable do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hearthside-mentionable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Hearth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activejob
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: microformats
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: railties
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocktail
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Webmention sending and receiving for Rails projects.
140
+ email:
141
+ - caleb@calebhearth.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - LICENSE.md
147
+ - README.md
148
+ - Rakefile
149
+ - app/assets/config/mentionable_manifest.js
150
+ - app/assets/stylesheets/mentionable/application.css
151
+ - app/assets/stylesheets/mentionable/mentions.css
152
+ - app/controllers/mentionable/application_controller.rb
153
+ - app/controllers/mentionable/mentions_controller.rb
154
+ - app/helpers/mentionable/application_helper.rb
155
+ - app/jobs/mentionable/application_job.rb
156
+ - app/jobs/mentionable/confirm_mention_job.rb
157
+ - app/jobs/mentionable/save_mention_job.rb
158
+ - app/jobs/mentionable/verify_with_router_job.rb
159
+ - app/mailers/mentionable/application_mailer.rb
160
+ - app/models/mentionable/application_record.rb
161
+ - app/models/mentionable/mention.rb
162
+ - app/views/layouts/mentionable/application.html.erb
163
+ - config/environment.rb
164
+ - config/routes.rb
165
+ - db/migrate/20200609182614_create_mentionable_mentions.rb
166
+ - db/migrate/20230121215844_add_status_and_html_and_microformats_to_mentions.rb
167
+ - lib/h.rb
168
+ - lib/h/adr.rb
169
+ - lib/h/base.rb
170
+ - lib/h/card.rb
171
+ - lib/h/cite.rb
172
+ - lib/h/entry.rb
173
+ - lib/mentionable.rb
174
+ - lib/mentionable/configuration.rb
175
+ - lib/mentionable/engine.rb
176
+ - lib/mentionable/version.rb
177
+ - lib/tasks/mentionable_tasks.rake
178
+ homepage: https://github.com/calebthompson/mentionable
179
+ licenses:
180
+ - Hippocratic 2.1
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubygems_version: 3.4.4
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Webmentions on Rails
201
+ test_files: []