Code Monkey home page Code Monkey logo

data_processor's Introduction

Data Processor

Parse YAML and Markdown files, manipulate their data and convert it to JSON.

Dependencies

  • Redcarpet
  • Oj

How it works

File structure:

/example_path/en/base.yaml
/example_path/en/pages/index.yaml
/example_path/en/pages/index.md

JSON Output: (by using the code below)

{
  "en": {
    "is_directory": true,
    "locale": "en",
    
    "base": {
      "value_from_base_yaml": "1"
    },
    
    "pages": {
      "is_directory": true,
      
      "index": {
        "title": "Homepage Title",
        "slug": "homepage-title",
        
        "parsed_markdown": "<p>Parsed markdown from index.md</p>",
        
        "is_yaml": true,
        "is_markdown": true
      }
    }
  }
}

Ruby Hash:

Pretty much the same as the JSON output, strings as keys, not symbols.

Usage

# New instance
# -> takes path as first argument, default is current directory
d = DataProcessor.new("/")

# Import data
# -> takes path as first argument, default is initial directory
d.import("example_path/")

# Manipulate data
# -> 1st arg, the path without file extension (string)
# -> 2nd arg, override, obj will be set to the return value of the block (boolean, optional)
# -> block to execute manipulations in
d.manipulate("en") { |obj| obj["locale"] = "en" }
d.manipulate("en/pages/index") { |obj| obj["slug"] = obj["title"].to_slug }

# Output
d.get_data # ruby hash
d.output_json # json

Install

# Gemfile
gem 'data_processor'

Markdown

Redcarpet is used here to parse markdown. You can override the markdown renderer by overriding DataProcessor::markdown_renderer, which returns a renderer.

data_processor's People

Contributors

icidasset avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.