What about having the builder implement Map?


On Thu, Apr 18, 2013 at 12:36 AM, Alex Soto <notifications@github.com>wrote:

> In src/main/java/org/asciidoc/maven/AsciidoctorMojo.java:
>
> > -
> > -        try {
> > -            final InputStream script = getClass().getClassLoader().getResourceAsStream("execute_asciidoctor.rb");
> > -            final InputStreamReader streamReader = new InputStreamReader(script);
> > -            rubyEngine.eval(streamReader, bindings);
> > -        } catch (ScriptException e) {
> > -            getLog().error("Error running ruby script", e);
> > +        final Asciidoctor instance = Asciidoctor.Factory.create();
> > +        final List<File> asciidocFiles = new AsciidocDirectoryWalker(sourceDirectory.getAbsolutePath()).scan();
> > +
> > +        final OptionsBuilder optionsBuilder = OptionsBuilder.options().toDir(outputDirectory).compact(compact)
> > +                .headerFooter(headerFooter).safe(SafeMode.UNSAFE).templateDir(templateDir).templateEngine(templateEngine);
> > +        final AttributesBuilder attributesBuilder = AttributesBuilder.attributes().backend(backend).docType(doctype)
> > +                .imagesDir(imagesDir).sourceHighlighter(sourceHighlighter).title(title);
> > +
> > +        // FIXME: There needs to be a better way to do this -- talk to Alex
>
> I agree with you that this should be changed, but at time I was writing
> this code, I knew it would be a really nice approach using a builder
> approach to set options/attributes, but it is true that calling two asMap
> is a bit redundant. I thought about attributes method returning the
> AttributesBuilder so you can integrate all of them inside a single call,
> something like:
>
> Map att = OptionsBuilder.options().toDir(outputDirectory).attributes().backend(backend).asMap();
>
> but this approach could mean that when you start defining attributes you
> cannot set more options, or for example I could implement something like:
>
> Map att = OptionsBuilder.options().toDir(outputDirectory).attributes().backend(backend).get().compact(compact).asMap();
>
> With that approach you can still setting options after setting attributes,
> but as you can see you need the get() terminator.
>
> But of course you could avoid using the terminator, but in this case you
> must duplicate the methods of options builder inside attribute builder.
>
> For this reason I decided to keep as simple as possible at first version,
> but we can think another approach of course.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/asciidoctor/asciidoctor-maven-plugin/pull/22/files#r3847637>
> .
>



-- 
Jason Porter
http://en.gravatar.com/lightguardjp