Skip to content

Instantly share code, notes, and snippets.

@bess
Forked from cbeer/dscm-to-html.rb
Created July 23, 2010 18:25
Show Gist options
  • Select an option

  • Save bess/487831 to your computer and use it in GitHub Desktop.

Select an option

Save bess/487831 to your computer and use it in GitHub Desktop.

Revisions

  1. cbeer created this gist Jul 23, 2010.
    86 changes: 86 additions & 0 deletions dscm-to-html.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    #!/usr/bin/env ruby
    #
    # ./dscm-to-html.rb repository_url PID
    #
    require 'rubygems'
    require 'nokogiri'
    require 'open-uri'
    require 'erb'
    require 'active_support'

    base_url = ARGV[0]
    pid = ARGV[1]

    doc = Nokogiri::XML(open(base_url + '/get/' + pid + '/DS-COMPOSITE-MODEL'))

    template = ERB.new <<-EOF
    <style type="text/css">
    .fedora-datastream-content-model {
    border: 1px solid #333;
    }
    .fedora-datastream-content-model .pid { background-color: #FFA0A0;}
    .fedora-datastream-content-model th td {
    text-align: center; padding: 15px; border-bottom: 1px solid #333;
    }
    .fedora-datastream-content-model td {
    padding: 15px; border-top: 1px solid #ccc;
    }
    .fedora-datastream-content-model .datastream {
    background-color: #E0E0FF;
    }
    .fedora-datastream-content-model .text-xml {
    background-color: #CCCCFF;
    }
    .fedora-datastream-content-model .video {
    background-color: #CCFFCC;
    }
    .fedora-datastream-content-model .system {
    background-color: #FFE0C0;
    }
    .fedora-datastream-content-model .pid {
    background-color: #FFA0A0;
    }
    .fedora-datastream-content-model .dc-title {
    font-size: .6em;
    }
    </style>
    <table class="fedora-datastream-content-model">
    <thead>
    <tr>
    <th><%= pid %></th>
    </tr>
    </thead>
    <tbody>
    <!-- System Datastreams -->
    <tr class="system pid"><td>Persistent ID (PID)</td></tr>
    <tr class="system text-xml text"><td>AUDIT (text/xml)</td></tr>
    <tr class="system text-xml text"><td>DC (text/xml)</td></tr>
    <tr class="system text-xml text"><td>RELS-EXT (text/xml)</td></tr>
    <!-- User Datastreams -->
    <% doc.xpath('//dscm:dsTypeModel', 'dscm' => 'info:fedora/fedora-system:def/dsCompositeModel#').reject { |ds| ['DC', 'RELS-EXT'].include? ds.xpath('@ID').to_s }.each do |ds| %>
    <tr class="datastream <%= ds.xpath('dscm:form/@MIME', 'dscm' => 'info:fedora/fedora-system:def/dsCompositeModel#').map { |x| [x.to_s.parameterize, x.to_s.split('/').first.parameterize].join(' ') }.join(' ') %>">
    <td><%= "%s (%s)" % [ds.xpath('@ID').to_s, ds.xpath('dscm:form/@MIME', 'dscm' => 'info:fedora/fedora-system:def/dsCompositeModel#').map { |x| x.to_s }.join('; ')] %>
    <% unless ds.xpath('dc:title', 'dc' => 'http://purl.org/dc/terms/').empty? %>
    <div class="dc-title"><%= ds.xpath('dc:title', 'dc' => 'http://purl.org/dc/terms/').first.text %></div>
    <% end %>
    </td>
    </tr>
    <% end %>
    </tbody>
    </table>
    EOF

    puts template.result(binding)