Project

ogg

0.0
No commit activity in last 3 years
No release in over 3 years
Ogg is an Open Graph Generator.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Ogg

Build Status

Ogg is an Open Graph Generator, support Basic Metadata, Optional Metadata, Structured Properties at present.

Whats is Open Graph?

Installation

add this line to your Gemfile. gem 'ogg'

or

$ gem install ogg

Usage

Basic

Basic style.

require 'ogg'

ogg = Ogg.new
ogg.title = 'Site Title'
ogg.type  = 'Article'
ogg.description = 'Description'
ogg.url   = 'http://example.com/'
ogg.image = 'http://example.com/example.png'
ogg.html

Ogg support new method with block.

ogg = Ogg.new do |o|
  o.title = 'Site Title'
  o.type  = 'Article'
  o.description = 'Description'
  o.url   = 'http://example.com/'
  o.image = 'http://example.com/example.png'
end
ogg.html

:raise

If you set :raise option and basic properties are inadequacy, occurs InvalidBasicProperty.

ogg = Ogg.new(:raise => true)
begin
  ogg.html 
rescue InvalidBasicProperty
  puts "called"
end

Structured Properties

like accessor

ogg = Ogg.new do |o|
  o.image.url        = "http://example.com/example.png"
  o.image.secure_url = "https://example.com/example.png"
  o.image.type       = "image/png"
  o.image.width      = "400"
  o.image.height     = "300"

  o.video.secure_url = "https://example.com/example.swf"
  o.video.type       = "application/x-shockwave-flash"
  o.video.width      = "400"
  o.video.height     = "300"

  o.audio.secure_url = "https://example.com/example.mp3"
  o.audio.type       = "audio/mpeg"
end
ogg.html

like hash

ogg = Ogg.new do |o|
  o.image[:url]        = "http://example.com/example.png"
  o.image[:secure_url] = "https://example.com/example.png"
  o.image[:type]       = "image/png"
  o.image[:width]      = "400"
  o.image[:height]     = "300"

  o.video[:secure_url] = "https://example.com/example.swf"
  o.video[:type]       = "application/x-shockwave-flash"
  o.video[:width]      = "400"
  o.video[:height]     = "300"

  o.audio[:secure_url] = "https://example.com/example.mp3"
  o.audio[:type]       = "audio/mpeg"
end
ogg.html

Generate html

ogg = Ogg.new
ogg.title = 'Site Title'
ogg.type  = 'Article'
ogg.description = 'Description'
ogg.url   = 'http://example.com/'
ogg.image = 'http://example.com/example.png'

html

ogg.html #=>
=begin
<meta property="og:title" content="Site Title">
<meta property="og:type" content="Article">
<meta property="og:description" content="Description">
<meta property="og:url" content="http://example.com/">
<meta property="og:image" content="http://example.com/example.png">
=end

basic_properties

ogg.basic_properties #=>
=begin
<meta property="og:title" content="Site Title">
<meta property="og:type" content="Article">
<meta property="og:url" content="http://example.com/">
<meta property="og:image" content="http://example.com/example.png">
=end

optional_properties

ogg.optional_properties #=> <meta property="og:description" content="Description">

Contributing

  1. fork the project.
  2. create your feature branch. (git checkout -b my-feature)
  3. commit your changes. (git commit -am 'commit message')
  4. push to the branch. (git push origin my-feature
  5. send pull request.

License

the MIT License