Sha256: 7ca24cbc5528017fe51417b145b6464a695588d0af0f79bb98a02f91488f2f4f

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

# 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)_

```json
{
  "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

```ruby
# 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
```



## Markdown

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_processor-0.1.0 README.md