Skip to content

Commit ed3373e

Browse files
committed
Freshmark-ified jscriptbox.
1 parent 4062b91 commit ed3373e

File tree

2 files changed

+13
-102
lines changed

2 files changed

+13
-102
lines changed

README.md

Lines changed: 10 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -6,115 +6,25 @@ output = [
66
link(shield('Javadoc', 'javadoc', 'OK', 'blue'), 'https://{{org}}.github.io/{{name}}/javadoc/{{stable}}/'),
77
link(shield('License Apache', 'license', 'Apache', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'),
88
'',
9-
link(shield('Changelog', 'changelog', '{{version}}', 'bright-green'), 'CHANGES.md'),
9+
link(shield('Changelog', 'changelog', '{{version}}', 'brightgreen'), 'CHANGES.md'),
1010
link(image('Travis CI', 'https://travis-ci.org/{{org}}/{{name}}.svg?branch=master'), 'https://travis-ci.org/{{org}}/{{name}}')
11-
'',
12-
link(shield('Gradle', 'supported', 'https://github.com/diffplug/spotless#adding-spotless-to-java-source', 'green'), 'CHANGES.md'),
13-
link(shield('CLI', 'supported', '{{version}}', 'green'), 'CHANGES.md'),
14-
].join('\n')
11+
].join('\n');
1512
-->
16-
[![Maven artifact](https://img.shields.io/badge/mavenCentral-com.diffplug.durian%3Adurian-blue.svg)](https://bintray.com/diffplug/opensource/durian/view)
17-
[![Latest version](http://img.shields.io/badge/latest-3.2.0-blue.svg)](https://github.com/diffplug/durian/releases/latest)
18-
[![Javadoc](http://img.shields.io/badge/javadoc-OK-blue.svg)](https://diffplug.github.io/durian/javadoc/3.2.0/)
19-
[![License](https://img.shields.io/badge/license-Apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
13+
[![Maven artifact](https://img.shields.io/badge/mavenCentral-com.diffplug.jscriptbox%3Ajscriptbox-blue.svg)](https://bintray.com/diffplug/opensource/jscriptbox/view)
14+
[![Latest version](https://img.shields.io/badge/latest-3.0.0-blue.svg)](https://github.com/diffplug/jscriptbox/releases/latest)
15+
[![Javadoc](https://img.shields.io/badge/javadoc-OK-blue.svg)](https://diffplug.github.io/jscriptbox/javadoc/3.0.0/)
16+
[![License Apache](https://img.shields.io/badge/license-Apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
2017

21-
[![Changelog](http://img.shields.io/badge/changelog-3.3.0--SNAPSHOT-brightgreen.svg)](CHANGES.md)
22-
[![Travis CI](https://travis-ci.org/diffplug/durian.svg?branch=master)](https://travis-ci.org/diffplug/durian)
18+
[![Changelog](https://img.shields.io/badge/changelog-3.1.0--SNAPSHOT-brightgreen.svg)](CHANGES.md)
19+
[![Travis CI](https://travis-ci.org/diffplug/jscriptbox.svg?branch=master)](https://travis-ci.org/diffplug/jscriptbox)
2320
<!---freshmark /shields -->
2421

25-
Generating URL's for the buttons above is tricky. Once they're generated, it's hard to keep them up-to-date as new versions are released. FreshMark solves the "Markdown with variables" problem by embedding tiny JavaScript SCRIPTs into the comments of your Markdown, which statically generate the rest of the document. By running these SCRIPTs as part of your build script, your project's documentation will always stay up-to-date.
26-
27-
Here is what the code looks like for the shields at the top of this document:
2822

29-
```javascript
30-
<!---freshmark shields
31-
output = [
32-
link(shield('Maven artifact', 'mavenCentral', '{{group}}:{{name}}', 'blue'), 'https://bintray.com/{{org}}/opensource/{{name}}/view'),
33-
link(shield('Latest version', 'latest', '{{stable}}', 'blue'), 'https://github.com/{{org}}/{{name}}/releases/latest'),
34-
link(shield('Javadoc', 'javadoc', 'OK', 'blue'), 'https://{{org}}.github.io/{{name}}/javadoc/{{stable}}/'),
35-
link(shield('License Apache', 'license', 'Apache', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'),
36-
].join('\n')
37-
-->
38-
... (the results from the last time that FreshMark was run)
39-
<!---freshmark /shields -->
40-
```
41-
42-
In addition to generating Markdown from scratch, FreshMark can also modify existing Markdown. This ensures that any inline documentation links stay fresh.
43-
44-
```javascript
4523
<!---freshmark javadoc
46-
output = prefixDelimReplace(input, 'https://{{org}}.github.io/{{name}}/javadoc/', '/', stable)
24+
output = prefixDelimiterReplace(input, 'https://{{org}}.github.io/{{name}}/javadoc/', '/', stable);
4725
-->
48-
To run FreshMark on some text, call [FreshMark.compile()](https://diffplug.github.io/freshmark/javadoc/1.0/com/diffplug/freshmark/FreshMark.html)
49-
<!---freshmark /javadoc -->
50-
```
51-
52-
## How it works
53-
54-
FreshMark has three pieces, `SECTION`, `SCRIPT`, and `BODY`. They are parsed as shown below:
55-
56-
```javascript
57-
<!---freshmark SECTION (identifier)
58-
SCRIPT (javascript)
59-
-->
60-
BODY (markdown)
61-
<!---freshmark /SECTION -->
62-
```
63-
64-
When `SCRIPT` is run, there are two magic variables:
65-
66-
* `input` - This is everything inside of BODY (guaranteed to have only unix newlines at runtime)
67-
* `output` - The script must assign to this variable. FreshMark will generate a new string where the `BODY` section has been replaced with this value.
6826

69-
Only four functions are provided:
70-
71-
* `link(text, url)` - returns a markdown link
72-
* `image(altText, url)` - returns a markdown image
73-
* `shield(altText, subject, status, color)` - returns a markdown image generated by [shields.io](http://shields.io/).
74-
* `prefixDelimReplace(input, prefix, delimiter, replace)` - updates URLs which contain version numbers.
75-
* example: for parameters `prefix='http://website/', delimiter='/', replace='2.0'`
76-
* input `[entry point](http://website/1.2/docs/entryPoint)` would be transformed into `[entry point](http://website/2.0/docs/entryPoint)`
77-
78-
It's full ECMAScript 5.1, so you can define any other functions you like, but these should be all you need.
79-
80-
When you run FreshMark, you can supply it with a map of key-value pairs using the command line or via a properties file. If you're running FreshMark from a build system plugin such as Gradle, then all of your project's metadata will automatically be supplied. These key-value pairs are used in the following way:
81-
82-
* Before `SCRIPT` is executed, any `{{key}}` templates will be substituted with their corresponding value.
83-
* When `SCRIPT` is executed, all of these key-value pairs are available as variables.
84-
85-
## How to run it
86-
87-
At the moment, you can run FreshMark using [Gradle](#gradle), the [console](#console), or the [Java API](#java-api directly. If you need a different way to run FreshMark, build it and submit a PR! We'd be happy to help [in Gitter](https://gitter.im/diffplug/freshmark).
88-
89-
### Gradle
90-
91-
Integration with Gradle is provided through the [Spotless](https://github.com/diffplug/spotless) plugin. Spotless can also enforce lots of style rules as well (tab vs whitespace, Java import ordering, etc), but it's completely a-la-carte. To just apply FreshMark to all of the markdown in your project (and nothing else), simply add this to your `build.gradle`:
92-
93-
```groovy
94-
plugins {
95-
id 'com.diffplug.gradle.spotless' version '1.4.0'
96-
}
97-
98-
spotless {
99-
freshmark '**/*.md'
100-
}
101-
```
102-
103-
See the [spotless docs] for more details.
104-
105-
### CLI
106-
107-
This repo is a command line application. Just run `freshmark.bat` (Windows) or `freshmark` (Linux and Mac) to run it.
108-
109-
```
110-
freshmark --help
111-
112-
113-
```
114-
115-
### Java API
116-
117-
There's just one class that really matters. If you want to add more functions, change which variables are there, make the behavior depend on the section name, etc, just take a peek at [FreshMark.java](src/main/java/com/diffplug/freshmark/FreshMark.java).
27+
<!---freshmark /javadoc -->
11828

11929
## Acknowledgements
12030
* Scripts run by [JScriptBox](https://github.com/diffplug/jscriptbox).

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
// code formatting
3-
id "com.diffplug.gradle.spotless" version "1.2.0"
4-
// bintray upload
3+
id "com.diffplug.gradle.spotless" version "1.3.0"
4+
// bintray uploading
55
id "com.jfrog.bintray" version "1.3.1"
66
}
77

@@ -62,6 +62,7 @@ spotless {
6262
trimTrailingWhitespace()
6363
endWithNewline()
6464
}
65+
freshmark {}
6566
}
6667

6768
//////////////

0 commit comments

Comments
 (0)