From 65bc45ee208030e194aace0220c26cffa19f1903 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 29 Sep 2014 14:53:31 +0100 Subject: [PATCH] Add README.adoc processor --- README.adoc | 41 +++++++++++++++++ pom.xml | 32 +++++++++++++ src/main/asciidoc/README.adoc | 5 ++ README.md => src/main/asciidoc/install.adoc | 3 +- src/main/asciidoc/intro.adoc | 3 ++ src/main/asciidoc/spring-cloud-cli.adoc | 35 ++------------ src/main/ruby/generate_readme.sh | 10 ++++ src/main/ruby/readme.rb | 51 +++++++++++++++++++++ 8 files changed, 147 insertions(+), 33 deletions(-) create mode 100644 README.adoc create mode 100644 src/main/asciidoc/README.adoc rename README.md => src/main/asciidoc/install.adoc (87%) create mode 100644 src/main/asciidoc/intro.adoc create mode 100755 src/main/ruby/generate_readme.sh create mode 100644 src/main/ruby/readme.rb diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..20d47a1 --- /dev/null +++ b/README.adoc @@ -0,0 +1,41 @@ +// Do not edit this file (go instead to src/main/asciidoc) + +Spring Boot command line features for +[Spring Cloud](https://github.com/spring-cloud). + + +== Installation + +To install, make +sure you have +[Spring Boot CLI](https://github.com/spring-projects/spring-boot) +(1.1.x with x>=5): + + $ spring version + Spring CLI v1.1.5.RELEASE + +E.g. for GVM users + +``` +$ gvm install springboot 1.1.5.RELEASE +$ gvm use springboot 1.1.5.RELEASE +``` + +then get the install command plugin (backported from Boot 1.2.0): + +``` +$ wget http://dl.bintray.com/dsyer/generic/install-0.0.1.jar +``` + +install it in the Spring Boot CLI, e.g. with GVM (MacOS users that rely on brew might have to find the `/lib` directory by scanning `brew info springboot`): + +``` +$ cp install-0.0.1.jar ~/.gvm/springboot/1.1.5.RELEASE/lib +``` + +and finally install the Spring Cloud plugin: + +``` +$ mvn install +$ spring install org.springframework.cloud:spring-cloud-cli:1.0.0.BUILD-SNAPSHOT +``` diff --git a/pom.xml b/pom.xml index 4848135..f74bbcc 100644 --- a/pom.xml +++ b/pom.xml @@ -43,4 +43,36 @@ + + + + maven-antrun-plugin + + + org.jruby + jruby-complete + 1.7.12 + + + + + readme + process-resources + + run + + false + + + + + + + + + + + + + diff --git a/src/main/asciidoc/README.adoc b/src/main/asciidoc/README.adoc new file mode 100644 index 0000000..bedb1c7 --- /dev/null +++ b/src/main/asciidoc/README.adoc @@ -0,0 +1,5 @@ +include::intro.adoc[] + +== Installation + +include::install.adoc[] diff --git a/README.md b/src/main/asciidoc/install.adoc similarity index 87% rename from README.md rename to src/main/asciidoc/install.adoc index 3b87583..3461132 100644 --- a/README.md +++ b/src/main/asciidoc/install.adoc @@ -1,5 +1,4 @@ -Spring Boot command line features for -[Spring Cloud](https://github.com/spring-cloud). To install, make +To install, make sure you have [Spring Boot CLI](https://github.com/spring-projects/spring-boot) (1.1.x with x>=5): diff --git a/src/main/asciidoc/intro.adoc b/src/main/asciidoc/intro.adoc new file mode 100644 index 0000000..db6c723 --- /dev/null +++ b/src/main/asciidoc/intro.adoc @@ -0,0 +1,3 @@ +Spring Boot command line features for +[Spring Cloud](https://github.com/spring-cloud). + diff --git a/src/main/asciidoc/spring-cloud-cli.adoc b/src/main/asciidoc/spring-cloud-cli.adoc index 3b87583..09822ec 100644 --- a/src/main/asciidoc/spring-cloud-cli.adoc +++ b/src/main/asciidoc/spring-cloud-cli.adoc @@ -1,34 +1,7 @@ -Spring Boot command line features for -[Spring Cloud](https://github.com/spring-cloud). To install, make -sure you have -[Spring Boot CLI](https://github.com/spring-projects/spring-boot) -(1.1.x with x>=5): += Spring Boot CLoud CLI - $ spring version - Spring CLI v1.1.5.RELEASE +include::intro.adoc[] -E.g. for GVM users +== Installation -``` -$ gvm install springboot 1.1.5.RELEASE -$ gvm use springboot 1.1.5.RELEASE -``` - -then get the install command plugin (backported from Boot 1.2.0): - -``` -$ wget http://dl.bintray.com/dsyer/generic/install-0.0.1.jar -``` - -install it in the Spring Boot CLI, e.g. with GVM (MacOS users that rely on brew might have to find the `/lib` directory by scanning `brew info springboot`): - -``` -$ cp install-0.0.1.jar ~/.gvm/springboot/1.1.5.RELEASE/lib -``` - -and finally install the Spring Cloud plugin: - -``` -$ mvn install -$ spring install org.springframework.cloud:spring-cloud-cli:1.0.0.BUILD-SNAPSHOT -``` +include::install.adoc[] diff --git a/src/main/ruby/generate_readme.sh b/src/main/ruby/generate_readme.sh new file mode 100755 index 0000000..a6b3611 --- /dev/null +++ b/src/main/ruby/generate_readme.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +base_dir = File.join(File.dirname(__FILE__),'../../..') +src_dir = File.join(base_dir, "/src/main/asciidoc") +require File.join(File.dirname(__FILE__), 'readme.rb') + +options = {} +ARGV.length > 0 and options[:to_file] = ARGV[0] + +SpringCloud::Build.render_file("#{src_dir}/README.adoc", options) diff --git a/src/main/ruby/readme.rb b/src/main/ruby/readme.rb new file mode 100644 index 0000000..2f532aa --- /dev/null +++ b/src/main/ruby/readme.rb @@ -0,0 +1,51 @@ +module SpringCloud + module Build + + IncludeDirectiveRx = /^\\?include::([^\[]+)\[(.*?)\]$/ + + class << self + + def process_include out, src, target, attrs + unless target.start_with?('/') + target = File.new(File.join(src, target)) + else + target = File.new(target) + end + target.each do |line| + self.process(out, File.dirname(target), line) + end + end + + def process out, src, line + if ((escaped = line.start_with?('\\include::')) || line.start_with?('include::')) && (match = IncludeDirectiveRx.match(line)) + if escaped + out << line[1..-1] + else + self.process_include out, src, match[1], match[2].strip + end + else + out << line + end + end + + def render_file file, options = {} + + srcDir = File.dirname(file) + out = ["// Do not edit this file (go instead to src/main/asciidoc)\n","\n"] + File.new(file).each do |line| + self.process(out, srcDir, line) + end + + unless options[:to_file] + puts out + else + writer = File.new(options[:to_file],'w+') + out.each { |line| writer.write(line) } + end + + end + + end + + end +end