~mro/Photos2Atom

bfbc5aa8305e1cb9f5a7f80806f6f0e02e76d0ea — Marcus Rohrmoser 8 years ago bca06af
Atom compliance++. refs #1
4 files changed, 38 insertions(+), 13 deletions(-)

M Photos2Atom.rb
A assets/atom-logo.svg
M assets/atom2html.xslt
A assets/valid-atom.png
M Photos2Atom.rb => Photos2Atom.rb +19 -13
@@ 66,7 66,9 @@ end
module MRO
  module Atom
    class Basic
      attr_reader :authors
      def initialize
        @authors = []
        @xml = ''
      end
      def id= v


@@ 82,12 84,11 @@ module MRO

    class Feed < Basic
      attr_writer :xslt
      attr_reader :links, :authors, :entries
      attr_reader :links, :entries

      def initialize
        super
        @links = []
        @authors = []
        @entries = []
        yield self
        self


@@ 163,6 164,9 @@ END_OF_XSLT
      def to_xml
        s = '<entry>'
        s <<= @xml
        s <<= '<author>'
        s <<= self.authors.join('')
        s <<= '</author>'
        s <<= self.links.join('')
        s <<= self.categories.join('')
        s <<= '</entry>'


@@ 189,9 193,7 @@ END_OF_XSLT
    end
    class Person < String
      def initialize h
        name = h[:name]
        h.delete :name
        super "<name #{h.map{|k,v| "#{k.to_xml}='#{v.to_xml}'"}.join(' ')}>#{name.to_xml}</name>"
        super h.map{|k,v| "<#{k}>#{v.to_xml}</#{k}>"}.join(' ')
      end
    end
    class Generator < String


@@ 346,9 348,11 @@ module MRO
      feed = Atom::Feed.new do |f|
        f.xslt = xslt_url
        f.title = @ALBUM_NAME
        f.links << Atom::Link.new(:href => @ATOM_URL, :rel => :self)
        f.generator = Atom::Generator.new(:uri => 'http://purl.mro.name/iPhoto2Atom', :name => 'iPhoto2Atom')
        f.authors << Atom::Person.new(:name => 'John Doe')
        f.links << Atom::Link.new(:href => @ATOM_URL, :rel => :self, :type => 'application/atom+xml')
        f.links << Atom::Link.new(:href => @ATOM_URL, :rel => :alternate, :type => 'text/html')
        f.generator = Atom::Generator.new(:uri => 'http://purl.mro.name/Photos2Atom', :name => 'iPhoto2Atom')
        artist = {:name => 'John Doe', :uri => 'http://example.com/~jd'}
        f.authors << Atom::Person.new(artist)
        f.id = @BASE_URL # "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
        prev = nil
        @IPHOTO.find_images_for_album(@ALBUM_NAME) do |row|


@@ 387,7 391,8 @@ module MRO
              e.updated = create_date
              maxDate = create_date if create_date > maxDate
              e.title = row[0] || row[1] # fallback to master name
              e.summary = row[10]
              e.summary = (row[10] || '').strip # is mandatory if content/@src
              e.authors << Atom::Person.new(artist)
              # use Rating ?
              dir2pxls.each do |dir,h|
                dst = File.join(@ATOM_DIR, dir, "#{sha}.#{dst_fmt}")              # (destination) file extension not part of sha.


@@ 409,8 414,8 @@ module MRO
                    # https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html
                    cyear = [create_date.year, Time.now.year].uniq.join('-')
                    properties = {
                      :copyright      => "© #{cyear}, Marcus Rohrmoser, http://mro.name/me",
                      :artist         => 'http://mro.name/me',
                      :copyright      => "© #{cyear}, #{artist[:name]}, #{artist[:uri]}",
                      :artist         => artist[:name],
                      :description    => [e.title, e.summary].collect{|s| '' == s ? nil : s}.compact.collect{|s| s.strip}.join(' / '),
                      :format         => dst_fmt,
                      :formatOptions  => h[:quality],


@@ 428,9 433,10 @@ module MRO
                else
                  $stderr.write '.'
                end
                e.links << Atom::Link.new(:href => (@ATOM_URL + (dir + '/') + "#{sha}.#{dst_fmt}"), :rel => h[:rel], :length => File.size(dst) )
                e.links << Atom::Link.new(:href => (@ATOM_URL + (dir + '/') + "#{sha}.#{dst_fmt}"), :rel => h[:rel], :length => File.size(dst), :type => "image/#{dst_fmt}" )
              end
              e.content = Atom::Content::External.new :src => (@ATOM_URL + ('1600p' + '/') + "#{sha}.#{dst_fmt}").to_s, :type => "image/#{dst_fmt}"
              e.links << Atom::Link.new(:href => (@ATOM_URL + ('1600p' + '/') + "#{sha}.#{dst_fmt}"), :type => "image/#{dst_fmt}" )
              e.content = Atom::Content::External.new :src => (@ATOM_URL + ('1600p' + '/') + "#{sha}.#{dst_fmt}"), :type => "image/#{dst_fmt}"
              e.media_thumbnail = Media::Thumbnail.new :url => (@ATOM_URL + ('200p' + '/') + "#{sha}.#{dst_fmt}")
              @IPHOTO.find_keywords_for_image_version_id(row[8]) do |keywor|
                e.categories << Atom::Category.new( :scheme => @BASE_URL, :term => keywor, :label => keywor )

A assets/atom-logo.svg => assets/atom-logo.svg +16 -0
@@ 0,0 1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://intertwingly.net/blog/2010/04/15/HTML-to-Atom -->
<svg xmlns="http://www.w3.org/2000/svg" stroke-width="2" width="100" height="100" viewBox="-52 -53 100 100">
  <g fill="none">
    <ellipse stroke="#66899a" rx="6" ry="44"/>
    <ellipse stroke="#e1d85d" rx="6" ry="44" transform="rotate(-66)"/>
    <ellipse stroke="#80a3cf" rx="6" ry="44" transform="rotate(66)"/>
    <circle stroke="#4b541f" r="44"/>
  </g>
  <g fill="#66899a" stroke="white">
    <circle fill="#80a3cf" r="13"/>
    <circle cy="-44" r="9"/>
    <circle cx="-40" cy="18" r="9"/>
    <circle cx="40" cy="18" r="9"/>
  </g>
</svg>

M assets/atom2html.xslt => assets/atom2html.xslt +3 -0
@@ 147,6 147,9 @@

        <hr style="clear:left;"/>
        <p id="footer">
          <a title="Validate my Atom 1.0 feed" href="https://validator.w3.org/feed/check.cgi?url={a:link[@rel='self']/@href}">
          <img alt="Valid Atom 1.0" src="assets/valid-atom.png" style="border:0;width:88px;height:31px"/>
          </a><xsl:text> </xsl:text>
          <a href="https://validator.w3.org/check?uri=referer">
          <img alt="Valid XHTML 1.0 Strict" src="assets/valid-xhtml10-blue-v.svg" style="border:0;width:88px;height:31px"/>
          </a>

A assets/valid-atom.png => assets/valid-atom.png +0 -0