Skip to content
Permalink
Browse files

deps: Replace mofo with microformats for better h-event parsing and m…

…aintainability (#587)
  • Loading branch information...
aeschright committed Sep 16, 2019
1 parent d5ff304 commit d0513121ae1fd79aca5ef4a34a7aa9141cc9e239
Showing with 23 additions and 7,337 deletions.
  1. +22 −26 app/models/calagator/source/parser/hcal.rb
  2. +1 −2 calagator.gemspec
  3. +0 −46 vendor/gems/mofo-0.2.8/CHANGELOG
  4. +0 −18 vendor/gems/mofo-0.2.8/LICENSE
  5. +0 −55 vendor/gems/mofo-0.2.8/Manifest.txt
  6. +0 −200 vendor/gems/mofo-0.2.8/README
  7. +0 −25 vendor/gems/mofo-0.2.8/Rakefile
  8. +0 −2 vendor/gems/mofo-0.2.8/init.rb
  9. +0 −325 vendor/gems/mofo-0.2.8/lib/microformat.rb
  10. +0 −5 vendor/gems/mofo-0.2.8/lib/microformat/array.rb
  11. +0 −30 vendor/gems/mofo-0.2.8/lib/microformat/simple.rb
  12. +0 −24 vendor/gems/mofo-0.2.8/lib/microformat/string.rb
  13. +0 −11 vendor/gems/mofo-0.2.8/lib/microformat/time.rb
  14. +0 −3 vendor/gems/mofo-0.2.8/lib/mofo.rb
  15. +0 −9 vendor/gems/mofo-0.2.8/lib/mofo/adr.rb
  16. +0 −6 vendor/gems/mofo-0.2.8/lib/mofo/geo.rb
  17. +0 −15 vendor/gems/mofo-0.2.8/lib/mofo/hcalendar.rb
  18. +0 −35 vendor/gems/mofo-0.2.8/lib/mofo/hcard.rb
  19. +0 −15 vendor/gems/mofo-0.2.8/lib/mofo/hentry.rb
  20. +0 −6 vendor/gems/mofo-0.2.8/lib/mofo/hfeed.rb
  21. +0 −17 vendor/gems/mofo-0.2.8/lib/mofo/hresume.rb
  22. +0 −14 vendor/gems/mofo-0.2.8/lib/mofo/hreview.rb
  23. +0 −6 vendor/gems/mofo-0.2.8/lib/mofo/rel_bookmark.rb
  24. +0 −6 vendor/gems/mofo-0.2.8/lib/mofo/rel_tag.rb
  25. +0 −66 vendor/gems/mofo-0.2.8/lib/mofo/xfn.rb
  26. +0 −54 vendor/gems/mofo-0.2.8/lib/mofo/xoxo.rb
  27. +0 −16 vendor/gems/mofo-0.2.8/mofo.gemspec
  28. +0 −384 vendor/gems/mofo-0.2.8/site/index.html
  29. BIN vendor/gems/mofo-0.2.8/site/mofo-logo.png
  30. +0 −2 vendor/gems/mofo-0.2.8/site/mootools.v1.00.js
  31. +0 −159 vendor/gems/mofo-0.2.8/site/style.css
  32. +0 −22 vendor/gems/mofo-0.2.8/test/base_url_test.rb
  33. +0 −80 vendor/gems/mofo-0.2.8/test/ext_test.rb
  34. +0 −69 vendor/gems/mofo-0.2.8/test/fixtures/bob.html
  35. +0 −1,052 vendor/gems/mofo-0.2.8/test/fixtures/chowhound.html
  36. +0 −403 vendor/gems/mofo-0.2.8/test/fixtures/corkd.html
  37. +0 −26 vendor/gems/mofo-0.2.8/test/fixtures/event_addr.html
  38. +0 −39 vendor/gems/mofo-0.2.8/test/fixtures/events.html
  39. +0 −1 vendor/gems/mofo-0.2.8/test/fixtures/fake.html
  40. +0 −535 vendor/gems/mofo-0.2.8/test/fixtures/fauxtank.html
  41. +0 −1,101 vendor/gems/mofo-0.2.8/test/fixtures/hatom.html
  42. +0 −409 vendor/gems/mofo-0.2.8/test/fixtures/hresume.html
  43. +0 −246 vendor/gems/mofo-0.2.8/test/fixtures/include_pattern_single_attribute.html
  44. +0 −5 vendor/gems/mofo-0.2.8/test/fixtures/simple.html
  45. +0 −225 vendor/gems/mofo-0.2.8/test/fixtures/stoneship.html
  46. +0 −335 vendor/gems/mofo-0.2.8/test/fixtures/upcoming.html
  47. +0 −479 vendor/gems/mofo-0.2.8/test/fixtures/upcoming_single.html
  48. +0 −200 vendor/gems/mofo-0.2.8/test/fixtures/xfn.html
  49. +0 −38 vendor/gems/mofo-0.2.8/test/hatom_test.rb
  50. +0 −33 vendor/gems/mofo-0.2.8/test/hcalendar_test.rb
  51. +0 −148 vendor/gems/mofo-0.2.8/test/hcard_test.rb
  52. +0 −23 vendor/gems/mofo-0.2.8/test/hresume_test.rb
  53. +0 −37 vendor/gems/mofo-0.2.8/test/hreview_test.rb
  54. +0 −27 vendor/gems/mofo-0.2.8/test/include_pattern_test.rb
  55. +0 −40 vendor/gems/mofo-0.2.8/test/reltag_test.rb
  56. +0 −34 vendor/gems/mofo-0.2.8/test/subclass_test.rb
  57. +0 −24 vendor/gems/mofo-0.2.8/test/test_helper.rb
  58. +0 −75 vendor/gems/mofo-0.2.8/test/xfn_test.rb
  59. +0 −49 vendor/gems/mofo-0.2.8/test/xoxo_test.rb
@@ -2,19 +2,17 @@
#
# Reads hCalendar events.

vendored_mofo_dir = File.expand_path('../../../../../vendor/gems/mofo-0.2.8/lib', File.dirname(__FILE__))
$: << vendored_mofo_dir
require 'mofo'
require 'microformats'

module Calagator
class Source::Parser::Hcal < Source::Parser
self.label = :hCalendar

EVENT_TO_HCALENDAR_FIELD_MAP = {
title: :summary,
title: :name,
description: :description,
start_time: :dtstart,
end_time: :dtend,
start_time: :start,
end_time: :end,
url: :url,
venue: :location
}.freeze
@@ -23,9 +21,9 @@ def to_events
hcals.map do |hcal|
event = Event.new
event.source = source
EVENT_TO_HCALENDAR_FIELD_MAP.each do |field, mofo_field|
next unless hcal.respond_to?(mofo_field)
next unless value = decoded_field(hcal, mofo_field)
EVENT_TO_HCALENDAR_FIELD_MAP.each do |field, hcal_field|
next unless hcal.respond_to?(hcal_field)
next unless value = decoded_field(hcal, hcal_field)

event.send "#{field}=", value
end
@@ -37,12 +35,12 @@ def to_events

private

def decoded_field(hcal, mofo_field)
return unless raw_field = hcal.send(mofo_field)
def decoded_field(hcal, hcal_field)
return unless raw_field = hcal.send(hcal_field)

decoded_field = case mofo_field
when :dtstart
HTMLEntities.new.decode(raw_field)
decoded_field = case hcal_field
when :start, :end
Time.parse(raw_field).in_time_zone
when :location
to_venue(raw_field)
else
@@ -51,7 +49,7 @@ def decoded_field(hcal, mofo_field)
end

VENUE_TO_HCARD_FIELD_MAP = {
title: :fn,
title: :name,
telephone: :tel,
email: :email,
description: :note
@@ -64,21 +62,21 @@ def decoded_field(hcal, mofo_field)
def to_venue(value)
venue = Venue.new
venue.source = source
case raw = value
case value
when String
venue.title = raw
when HCard
assign_fields(venue, raw)
assign_geo(venue, raw) if raw.respond_to?(:geo)
assign_address(venue, raw) if raw.respond_to?(:adr)
venue.title = value
when Microformats::ParserResult
assign_fields(venue, value)
assign_geo(venue, value) if value.respond_to?(:geo)
assign_address(venue, value) if value.respond_to?(:adr)
end
venue.geocode!
venue_or_duplicate(venue)
end

def assign_fields(venue, raw)
VENUE_TO_HCARD_FIELD_MAP.each do |field, mofo_field|
venue[field] = raw.send(mofo_field).try(:strip_html) if raw.respond_to?(mofo_field)
VENUE_TO_HCARD_FIELD_MAP.each do |field, hcal_field|
venue[field] = raw.send(hcal_field) if raw.respond_to?(hcal_field)
end
end

@@ -99,9 +97,7 @@ def assign_address(venue, raw)
end

def hcals
content = self.class.read_url(url)
something = hCalendar.find(text: content)
something.is_a?(hCalendar) ? [something] : something
Microformats.parse(url).items.select { |item| item.type == 'h-event' }
end
end
end
@@ -23,8 +23,6 @@ Gem::Specification.new do |s|
# When changing this Rails requirement, also update RAILS_REQUIREMENT in rails_template.rb
s.add_dependency 'rails', '~> 4.2'

# s.add_dependency "mofo", path: "vendor/gems/mofo-0.2.8" # vendored fork with hpricot dependency replaced with nokogiri

s.add_dependency 'acts-as-taggable-on', '~> 3.5'
s.add_dependency 'bluecloth', '~> 2.2'
s.add_dependency 'font-awesome-rails', '~> 4.3'
@@ -36,6 +34,7 @@ Gem::Specification.new do |s|
s.add_dependency 'loofah', '~> 2.0'
s.add_dependency 'loofah-activerecord', '>= 1.2', '< 3.0'
s.add_dependency 'lucene_query', '0.1'
s.add_dependency 'microformats', '~> 4.0.7'
s.add_dependency 'nokogiri'
s.add_dependency 'paper_trail_manager', '~> 0.5.0'
s.add_dependency 'rack-contrib', '~> 1.0'

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit d051312

Please sign in to comment.
You can’t perform that action at this time.