Git Product home page Git Product logo

ox_builder's Introduction

OxBuilder

XML builder with using ox. Fast and convenient DSL.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'ox_builder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ox_builder

Usage

  Ox::Builder.document do |document|
    document.element(
    'rss', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:atom' => 'http://www.w3.org/2005/Atom',
    'xmlns:media' => 'http://search.yahoo.com/mrss/', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/',
    'xmlns:itunes' => 'http://www.itunes.com/dtds/podcast-1.0.dtd', 'version' => '2.0'
  ) do |rss|
      rss.element('channel') do |channel|
        description(channel)

        Post.all do |post|
          channel_item(post)
        end
      end
    end
  end

  def description node
    node.element('title', 'Title of channel')
    node.element('link', 'http://www.example.com')
    node.element('description', 'Description of channel')
    node.element('language', 'ru')
    node.element('copyright', 'copyright')
  end

  def channel_post node, post
    node.element('item') do |item|
      node.element('title', post.title)
      node.element('link', post.permalink)
      node.element('guid', post.permalink)
      node.element('pubDate', post.published_at)
      node.element('description', post.description)
      node.element('category', post.category)
      mode.element('enclosure',  url: post.image.url, type: 'image/jpeg', length: post.image.size)
    end
  end

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

ox_builder's People

Contributors

undr avatar

Stargazers

Kirill Chernyshov avatar Josh Voigts avatar

Watchers

 avatar Kirill Chernyshov avatar James Cloos avatar

Forkers

delaguardo

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.