Coder Social home page Coder Social logo

jamesramsay / hercule Goto Github PK

View Code? Open in Web Editor NEW
221.0 221.0 24.0 2.31 MB

:recycle: Simple document transclusion, ideal for Markdown documents

License: MIT License

JavaScript 97.10% Dockerfile 0.41% PEG.js 2.49%
api-blueprint javascript markdown mson preprocessor transclusion

hercule's People

Contributors

bkuhl avatar dependabot-preview[bot] avatar dependabot[bot] avatar gitter-badger avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jamesramsay avatar mitmaro avatar realityking avatar vinteo avatar zkilgore avatar zuver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hercule's Issues

File not found errors crash gulp watch

First off, very helpful library, appreciate the hard work.

Working on documenting a large api using apiary and using hercule to handle various includes to make things a bit more manageable. I've written a simple gulp watcher to monitor changes and dump everything into the main .apib file, and all that works great. The only problem I've found is that when I screw up a file path hercule causes my gulp watcher to hang. I will get an error like 'Error: File (badfilename.md) not found.', and all execution stops. I can manually kill the task, fix the error and restart it, but that's not what I'm looking for. I don't claim to be a gulp expert, but I've tried various ways of error handling, and none have managed to catch the error.

I have found one solution to the problem. If I change the default return statement in readFile() (utils.js) from return null to return '' (empty string), then I will still get the error (which is good), but the task will continue and I can address my mistake without restarting.

So, am I missing something? Is there a best practice for this kind of error handling? Will this modification break something else in hercule that I haven't spotted yet?

Streamline npm version bump

Currently the npm version must be bumped manually for every release. Ideally a script should be used to increment, commit, tag and push to master.

  • master is currently protected which will need to be changed.

Support for HTTP links

Links currently must be relative file links. It could be interesting to reference remote files, but not sure what instances this would be particularly useful in...

Upgrade devDependencies

A number of dev dependencies have fallen behind:

  • babel (minor)
  • nock (minor)
  • eslint-config-airbnb (major)

Test hercule on multiple version

Travis should run tests against current versions (0.10, 0.12, 4, and 5)

Note that sync API relies on > node 0.12, and sync tests will need to be skipped.

Support partial file transclude

Using the syntax:

:[link to something](file.md#section-6)

Yet to be determined, what h (#) levels to support? From h1 to h3 or down to h6? How often does one need to include part of a document but not all of it?

White space in description causes errors?

According to the examples the below should be a valid link:

:[Example here](example.md)

However when I run it...
Running "hercule:docs" (hercule) task
Fatal error: Expected "]" or [a-zA-Z0-9] but " " found.

When I get rid of the white space the below works:

:[ExampleHere](example.md)

image

Fuzzy local link resolving

Hi there,

I'm trying to allow authors to transclude with a simpler link syntax in the same way that using permalinks in a static site generator allows to create links and forego the extensions (in an SSG by renaming something.html to something/index.html which means that [my permalink](something) works which is a more "human" link. I'd like to be able to do :[my permatransclusion](something) and have hercules try something and if asked to (with some kind of config flag I guess) then try to resolve something.md.

Would this be possible?

Cheers,

Jun

Better handle pegjs parsing errors

When peg crashes, no useful information is provided.

/Users/james.ramsay/Development/buyer-api/node_modules/hercule/lib/transclude-parser.js:907
      throw peg$buildException(
            ^
SyntaxError: Expected " ", [^ ()\"], [a-zA-Z0-9] or end of input but "\"" found.

This was triggered by a typo (bar: appears twice):

:[example][foo.md bar:bar:"fizz buzz"]

Blanket dependency

There seems to be some dependency on blanket for non dev installs.
After a 'npm install -g hercule', running hercule throws:

module.js:338
throw err;
^
Error: Cannot find module 'blanket'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/usr/local/lib/node_modules/hercule/lib/main.js:5:13)
at Object. (/usr/local/lib/node_modules/hercule/lib/main.js:80:4)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)

Relative path's not being handled correctly

To replicate:

index.md
foo/file1.md
foo/file2.md

index.md transcludes foo/file1.md, file1.md transcludes file2.md but file2 is incorrectly being searched for in the root rather than folder foo.

Increase test coverage of warning/error behaviours

  • Test for when file handling warning is shown
  • Test for when http handling warning is shown

Reporters:

  • tree
  • basic
  • json (used by sync API and pushes all log messages onto stderr for spawnSync to capture)

Subsequently defined placeholders clears previously defined placeholders?

File test.md sets a string placeholder to "venues":

:[](blueprints/venues.md resource:"venues")

File blueprints/venues.md

# Group Venues

## Add venues [/venues]

:[](post.md attributes:"Venue" description:"This and that")

File post.md is expected to just print the resource placeholder

:[](resource)

Now, transcluding test.md gives me the following error:

$ hercule --verbose doc/test.md -o doc/out/APIv2local.apib
Transcluding file... doc/test.md
Links found: 1
Transcluding: doc/blueprints/venues.md (file) into doc/blueprints/venues.md
Links found: 1
Transcluding: doc/blueprints/post.md (file) into doc/blueprints/post.md
Links found: 1
Error: File (doc/blueprints/resource) not found.
Transcluding: doc/blueprints/resource (file) into doc/blueprints/resource
Links found: 0

If I remove the placeholders in the second file, then all is well.
It seems to me, that subsequently defined placeholders will clear all previously defined placeholder during the transclusion, or am I just doing it wrong?

If this is a chosen or known limitation, then the possibility to merge placeholders would be a really nice feature.

Source maps for linting

When working on a large API Blueprint document spread over multiple files, it would be useful for linting (e.g. https://github.com/zdne/linter-api-blueprint) to provide the feedback based on the compiled output rather on each unit.

In order for this to be possible:

  • source map output from Hercule
  • linter would need to detect source map, identify which files are referenced from it so that they are linted based on compiled output rather than source

[discussion] Support for html strings in JSON

Is there possible to extract html - String from Body description

+Body

{
   field1: 'Value1'
   html: '<HEAD></HEAD><BODY></BODY>'
}

I don't need to extract whole body to JSON file, only HTML needed.

Remove event-stream dependency

es.map is only being used in a single location and can be simply replaced with through2 which is used through out the project.

Nested placeholders

Passing a placeholder via some included files will be very userful and makes my project less complicated.

first.md

:[](second.md placeholder:"John")

second.md

Hello :[name](placeholder)
:[](third.md placeholder:placeholder)

third.md

How are you, :[name](placeholder)?

Recursive transclusion

Not sure if it's intended to be supported or not (if not consider this a feature request), but would be good to transclude included files; i.e.

 file1.md:
 I want to transclude [ThisOne](file2.md)

file2.md:
And I'm so DRY and lazy I'd like to transclude [ThisOneHere](file3.md)

file3.md:
Must I do everything?

Error: Cannot find module 'blanket'

Just did a clean global install of Hercule. First attempt to run it:

module.js:338
    throw err;
          ^
Error: Cannot find module 'blanket'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/hercule/lib/main.js:5:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/hercule/lib/main.js:80:4)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

Mac OS X Yosemite

It did give me these errors upon installation though:

$ sudo npm install -g hercule
/usr/local/bin/hercule -> /usr/local/lib/node_modules/hercule/bin/transclude
npm WARN unmet dependency /usr/local/lib/node_modules/bower/node_modules/tar-fs/node_modules/tar-stream/node_modules/bl requires readable-stream@'~1.0.26' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/bower/node_modules/tar-fs/node_modules/tar-stream/node_modules/readable-stream,
npm WARN unmet dependency which is version 1.0.33-1
[email protected] /usr/local/lib/node_modules/hercule
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])

Contributor guidelines, commit message style guide and linting

Synchronous API

I'd really like a synchronous API for hercule. It's pretty simple to make a synchronous call become asynchronous—just wrap it in a setImmediate or similar—but it's rather hard to go the other direction. As best as I can tell the only thing keeping it synchronous is support for transcluding from an HTTP address. Would you be willing to make (or accept a pull request for) a version of hercule that works synchronously, dropping support for HTTP transcludes?

Default/Fallback Values

We are using hercule for generating our finished API Blueprint. By now a lot of thought and try/error went into how to best create DRY blueprints? and one thing that turned out to be very helpful were default values. So we have this atomic MSON objects, from whereon we generate (thanks to hercule) more complex MSON objects (which keeps everything super DRY). Now the problem is, that an MSON object might have slightly different settings based on where it gets used e.g. response vs. request (which makes the approach only super DRY, but not as DRY and flexible as possible). A quick example.

[file: title.md]
- title: None (string, required)

    The title

So in our response this atomic MSON object would be quite alright, but in our request we face the problem, that it might not be required, therefore we would have to repeat ourselves all over again. But support for default values could solve the problem.

[file: title.md]
- title: None (string, :[Presence Placeholder](presence || "required"))

    The title

Now we can reuse this atomic MSON object wherever we need it.

## Get Product Response Attribute

:[Product Title](title.md)

## Create Product Request Attribute

:[Product Title](title.md presence:"optional")

This also comes in handy for different sample values for different requests/responses and testing the blueprint with Dredd.

Now, if that is too abstract and a bigger picture is missing you can check out our example API Blueprint that documents and outlines how we use hercule to create DRY API Blueprints.

Also, I already wrote the code for providing support for default values. You can find the fork here.

I am not sure though if that is something that proves valuable to you, yet. Maybe you already have some thoughts about the support for default/fallback values? I am just curious what you think about it and if you could imagine to integrate something like this into the project.

Promises

Promises are a key part of ES2015 and should be supported by Hercule.

Library example throws error

In the Readme (https://github.com/jamesramsay/hercule#usage), there is an example describing how to use this library. This example does not currently work as described in node 4.2.1.

It specifically errors at the very start of transcludeStringSync in lib/hercule.js

function transcludeStringSync(input, _ref2, log) {
  var relativePath = _ref2.relativePath;

The example in the Readme does not provide a second parameter, so in the above function _ref2 does not exist, and accessing relativePath on _ref2 throws an error.

This is fixed by providing an object as the second parameter, with a relativePath property.

var hercule = require('hercule');

var output = hercule.transcludeStringSync("# Title\n\n:[abstract](abstract.md)", {
    relativePath: __dirname
});

console.log(output);

Which side of this problem do you think needs to be fixed? Is relativePath a required option? Or should the function declare that field optional?

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.