-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gherkin): 🚀 inner processor - full gherkin syntax support (#111)
Co-authored-by: Julien Boz <[email protected]>
- Loading branch information
Showing
11 changed files
with
218 additions
and
325 deletions.
There are no files selected for viewing
117 changes: 0 additions & 117 deletions
117
livingdoc-examples/microservice/src/main/livingdoc/gherkin_template.erb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
...ugin/src/main/java/ch/ifocusit/livingdoc/plugin/gherkin/GherkinToAsciidocTransformer.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...plugin/src/main/java/ch/ifocusit/livingdoc/plugin/gherkin/StandaloneGherkinProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch.ifocusit.livingdoc.plugin.gherkin; | ||
|
||
import com.github.domgold.doctools.asciidoctor.gherkin.MapFormatter; | ||
import lombok.Builder; | ||
import lombok.SneakyThrows; | ||
import org.apache.commons.io.IOUtils; | ||
import org.jruby.embed.ScriptingContainer; | ||
|
||
import java.io.File; | ||
import java.nio.charset.Charset; | ||
import java.util.Objects; | ||
|
||
@Builder | ||
public class StandaloneGherkinProcessor { | ||
|
||
private File gherkinTemplate; | ||
|
||
@SneakyThrows | ||
public String process(String fileContent) { | ||
ScriptingContainer container = new ScriptingContainer(); | ||
container.put("feature_file_content", fileContent); | ||
container.put("template_content", gherkinTemplate != null ? IOUtils.toString(gherkinTemplate.toURI(), Charset.defaultCharset()) : MapFormatter.getDefaultTemplate()); | ||
String scriptPath = "/standaloneGherkinProcessor.rb"; | ||
String script = IOUtils.toString(Objects.requireNonNull(getClass().getResourceAsStream(scriptPath)), Charset.defaultCharset()); | ||
return (String) container.runScriptlet(script); | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
livingdoc-maven-plugin/src/main/resources/plantuml_macro.mustache
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
livingdoc-maven-plugin/src/main/resources/standaloneGherkinProcessor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'erb' | ||
|
||
def preprocess_feature feature | ||
if feature.key?('background') | ||
preprocess_scenario feature['background'] | ||
end | ||
if feature.key?('scenarios') | ||
feature['scenarios'].each do |scenario| | ||
preprocess_scenario scenario | ||
end | ||
end | ||
end | ||
|
||
def preprocess_scenario scenario | ||
if scenario.key?('steps') | ||
preprocess_steplist scenario['steps'] | ||
end | ||
if scenario.key?('examples') | ||
preprocess_table_comments scenario['examples']['rows'] | ||
end | ||
end | ||
|
||
def preprocess_steplist steplist | ||
steplist.each do |step| | ||
if step.key?('rows') | ||
preprocess_table_comments step['rows'] | ||
end | ||
end | ||
end | ||
|
||
def preprocess_table_comments rows | ||
if rows.length > 0 && rows.first.key?('comments') && rows.first['comments'].length > 0 && rows.first['comments'].first['value'].match(/^#cols=/) | ||
cols = rows.first['comments'].first['value'][1..-1] | ||
rows.first['comments'].java_send :remove, [Java::int], 0 | ||
rows.first["cols"] = cols | ||
end | ||
rows.each do |row| | ||
if row.key?('comments') && row['comments'].length > 0 && row['comments'].first['value'].match(/^#cells=/) | ||
cells = row['comments'].first['value'][7..-1].split(/,/) | ||
row['cell-styles'] = cells | ||
row['comments'].java_send :remove, [Java::int], 0 | ||
end | ||
end | ||
end | ||
|
||
# parse feature and make the result available to the template via binding as 'feature' hash. | ||
feature = com.github.domgold.doctools.asciidoctor.gherkin.MapFormatter.parse(feature_file_content) | ||
|
||
preprocess_feature(feature) | ||
|
||
erb_template = ERB.new(template_content) | ||
rendered_template_output = erb_template.result(binding()) | ||
|
||
rendered_template_output |
Oops, something went wrong.