Coder Social home page Coder Social logo

atom-template-json's People

Contributors

pvienneau avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

esperdyne

atom-template-json's Issues

[Config] Save to Disk Toggle

As per @sartian's proposal, implement toggle switch in package settings to control if a file gets saved to disk or not.

Default: true

  1. If true:
    • File should be open as a tab in the editor.
    • File should be saved to disk, bearing same filename as .template.json file, with updated .json extension.
    • File should be saved inside same directory as related .template.json file.
    • Tab should be set to active.
  2. If false:
    • File should be open as a tab in the editor.
    • File should be bearing the same filename as .template.json file, with updated .json extension.
    • Tab should be set to active.

Feature Request: Add support for different templating dialects

Overview

I came across a template data generator called Dummy JSON which has a very similar syntax to this project. I initially was going to request some tweaks to more closely mimic features of Dummy JSON (synchronized helpers, overrides, arrays), but it seemed cleaner to simply suggest this package have a method for specifying different templating dialects. The default dialect is the one already supported by the package; if a user takes no special actions to specify a template dialect other than the out of the box dialect, it behaves as if different dialects don't exist and simply uses the default.

How it would work

I propose at the top of the template file there be limited support for bash/python/yaml "#" style comments as the JSON format doesn't support comments normally. We can borrow from a convention called File Variables used by Emacs and others text editors normally used to denote file encoding and other prefered behaviors at the heading of a file, like so where key/value pairs are delimited by semi-colons...

# -*- mode: python-mode; coding: utf-8; python-indent-offset: 4 -*-

...instead of the previous example, the first line of the template file would look more like one of these if specified:

  • # -*- template-dialect: pvienneau/atom-template-json -*-
  • # -*- template-dialect: webroo/dummy-json -*-
  • # -*- template-dialect: acme/some-other-dialect -*-

...or an even more simply: # template-dialect: webroo/dummy-json

The header comments could be stripped after initial parsing to pass the data through to the respective dialect parser. This concept could be leveraged to include fields that specify includes/overrides for sample data via a file or even inline.

If the package included a command-line tool, in linux shells template files could be set executable in conjunction with Shebang Notation so that scripts with a heading like so...

#!/usr/bin/env atom-template-json 
# template-dialect: webroo/dummy-json

...could run from the command line like so:

$ ./user.template.json --count 2000 > small-sample-user-set.json

Examples

Example 'out-of-the-box' template format as it is today:

{
    "users": [
        {{repeat(5)}}
        {
            "id": {{id()}},
            "guid": {{guid()}},
            "description": {{string(50)}},
            "birth_year": {{random(1975, 2005)}},
            "date_created": {{timestamp()}}
        }
    ]
}

Example of support for a different dialect

# template-dialect: webroo/dummy-json
{
  "users": [
    {{#repeat 2}}
    {
      "id": {{@index}},
      "name": "{{firstName}} {{lastName}}",
      "work": "{{company}}",
      "email": "{{email}}",
      "dob": "{{date '1900' '2000' 'YYYY'}}",
      "address": "{{int 1 100}} {{street}}",
      "city": "{{city}}",
      "optedin": {{boolean}}
    }
    {{/repeat}}
  ],
  "images": [
    {{#repeat 3}}
    "img{{@index}}.png"
    {{/repeat}}
  ],
  "coordinates": {
    "x": {{float -50 50 '0.00'}},
    "y": {{float -25 25 '0.00'}}
  },
  "price": "${{int 0 99999 '0,0'}}"
}

Closing

I have some complex JSON data I need to model and generate schemas and data for and this package comes very close to being exactly what I need, but some of the features of the other data generator are attractive as well. Instead of borrowing/replacing features, perhaps without too much effort the package could support one or more other rendering formats as well (Dummy, Faker, Chance, Casual, RandExpJs). In any case, thank you for this already useful atom package!

Uncaught TypeError: Cannot read property 'indexOf' of undefined

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.53.0 x64
Electron: 6.1.12
OS: Microsoft Windows 10 Enterprise
Thrown From: template-json package 0.0.9

Stack Trace

Uncaught TypeError: Cannot read property 'indexOf' of undefined

At C:\Users\thavaigi\.atom\packages\template-json\utils\path.js:3

TypeError: Cannot read property 'indexOf' of undefined
    at Object.module.exports.getFileExtension (/packages/template-json/utils/path.js:3:25)
    at Object.generate (/packages/template-json/lib/template-json.js:45:22)
    at HTMLElement.templateJsonGenerate (/packages/template-json/lib/template-json.js:29:50)
    at CommandRegistry.handleCommandEvent (~/AppData/Local/atom/app-1.53.0/resources/app/static/<embedded>:11:350265)
    at CommandRegistry.dispatch (~/AppData/Local/atom/app-1.53.0/resources/app/static/<embedded>:11:348740)
    at AtomEnvironment.dispatchApplicationMenuCommand (~/AppData/Local/atom/app-1.53.0/resources/app/static/<embedded>:1:767067)
    at EventEmitter.t (~/AppData/Local/atom/app-1.53.0/resources/app/static/<embedded>:1:774990)
    at EventEmitter.emit (events.js:200:13)
    at Object.onMessage (~/AppData/Local/atom/app-1.53.0/resources/electron.asar/renderer/init.js:42:16)

Commands

     -0:21.9.0 template-json:generate (div.tool-panel.tree-view)

Non-Core Packages

atom-ide-ui 0.13.0 
atom-json-editor 0.5.1 
ide-json 0.2.1 
ide-yaml 0.7.1 
language-flatbuffers 0.2.0 
template-json 0.0.9 

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.