Giter Club home page Giter Club logo

mods_display's Introduction

Build Status

ModsDisplay

A gem for displaying MODS Metadata in a configurable way.

Installation

Add this line to your application's Gemfile:

gem 'mods_display'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mods_display

Include the ModelExtension into your model.

class MyClass
  include ModsDisplay::ModelExtension
end

Configure the source of the MODS XML in your model. You can pass a string of XML to the mods_xml_source method, however it will also accept a block where you can call methods on self (so if the MODS XML string is held in MyClass#mods):

class MyClass
  ....
  
  mods_xml_source do |model|
    model.mods
  end
  
end

Include the ControllerExtension into your rails controller (or another class if not using rails).

class MyController
  include ModsDisplay::ControllerExtension
end

Optionally configure the mods display gem (more on configuration later).

class MyController
  ....
  configure_mods_display do
    ....
  end
end

Configuration

In the class that you include the ModsDisplay::ControllerExtension you can configure various behavior for different fields. The configuration options provided by ModsDisplay::Configuration::Base are:

  • label_class
  • value_class
  • delimiter
  • link

Label and Value classes

Both label_ and value_class accept strings to put in as a class.

class MyController
  include ModsDisplay::ControllerExtension
  
  configure_mods_display do
    title do
      label_class "title-label"
      value_class "title-value"
    end
  end
end

Delimiter

The delimiter configuration option accepts a string which will be used to delimit multiple multiple values within a single label.

configure_mods_display do
  note do
    delimiter "<br/>"
  end
end

Note: The default is a comma and a space (", ")

Link

The link configuration option takes 2 parameters. The first is a key that is a method_name available in the class including ModsDisplay::ControllerExtension and the 2nd is options to pass to that method. This method must return a string that will be used as the href attribute of the link. (NOTE: If you have the %value% token in your options that will be replaced with the value of the field being linked)

class MyController
  include ModsDisplay::ControllerExtension
  
  configure_mods_display do
    format do
      link :format_path, '"%value%"'
    end
  end
  
  def format_path(format)
    "http://example.com/?f[format_field][]=#{format}"
  end
end

Special Subject Configuration

Depending on the implementation of subjects there may be different ways you would want to link them. The standard way of linking will just create a link passing the value to the href and the link text. However; in certain cases the subjects should be linked so that each subject to the right of a delimiter should have the values of all its preceding values in the href.

Country > [State](http://example.com/?"Country State") > [City](http://example.com/?"Country State City")

This can be accomplished by setting the hierarchical_link configuration option to true for subjects

configure_mods_display do
  subject do
    hierarchical_link true
  end
end

NOTE: The default delimiter is set to > for subjects.

Usage

Once installed, the class that included the ControllerExtension (MyController) will have the render_mods_display method available. This method takes one argument which is an instance of the class that included the ModelExtension (MyClass).

render_mods_display(@model) # where @model.is_a?(MyClass)

The basic render call will return the top-level ModsDisplay::HTML class object. Any String method (e.g. #html_safe) you call on this top-level object will be sent down to the #to_html method which will return the HTML for all the metadata in the MODS document.

render_mods_display(@model).to_html

You can abstract the main title by calling #title on the top-level HTML method

render_mods_display(@model).title

When getting JUST the main title out of the metadata, it will be useful to get the rest of the metadata without the main title. You can accomplish this by calling #body on the top-level HTML object.

render_mods_display(@model).body

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

mods_display's People

Contributors

jkeck avatar

Watchers

Jon Deering avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.