Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Add support for compiling handlebars templates into a js file #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion componentbuild/shared/macrolib.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="YuiMacroLib">
<macrodef name="compilehandlebars">
<element name="sourcefiles" optional="false" />
<element name="outputfile" optional="false" />

<sequential>
<pathconvert pathsep="' '" property="sourcefilesargs">
<sourcefiles />
</pathconvert>
<exec executable="${handlebars.executable}" failifexecutionfails="true" failonerror="true">
<arg line="'${sourcefilesargs}' -f '${outputfile}'" />
</exec>
</sequential>
</macrodef>

<macrodef name="arrayliteral">
<attribute name="from" />
Expand Down Expand Up @@ -289,7 +302,7 @@
</else>
</if>

<copy file="${builddir}/files/langtemplate.txt" tofile="@{dest}/${@{module}@{lang}_fullname}.js" overwrite="true" outputencoding="utf-8">
<copy file="${langtemplate.file}" tofile="@{dest}/${@{module}@{lang}_fullname}.js" overwrite="true" outputencoding="utf-8">
<filterset>
<filter token="LANG" value="@{lang}" />
<filter token="LANG_MODULE" value="lang/${@{module}@{lang}_fullname}" />
Expand Down
8 changes: 8 additions & 0 deletions componentbuild/shared/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<property name="yuicompressor.jar" location="${builddir}/lib/yuicompressor/ant-yuicompressor-2.4.5pre2.jar" />
<property name="yrb2jsonconsole.js" location="${builddir}/lib/yrb2json/yrb2json-console.js" />
<property name="yrb2jsonsrc.js" location="${builddir}/lib/yrb2json/yrb2json.js" />
<property name="handlebars.executable" value="handlebars" />

<!-- YUI Compressor arguments for JS and CSS files -->

Expand Down Expand Up @@ -60,6 +61,10 @@
<property name="component.jsfiles.base" location="${component.basedir}/js" />
<property name="component.cssfiles.base" location="${component.basedir}/css" />

<property name="component.template.base" location="${component.basedir}/templates" />
<property name="component.template.files" value="**/*" />
<property name="compiled-templates.file" value="compiled-templates.js" />

<property name="component.lang.base" location="${component.basedir}/lang" />

<property name="component.assets.flatten" value="true" />
Expand Down Expand Up @@ -106,6 +111,9 @@
</and>
</condition>

<!-- Which file will be used for language template loader -->
<property name="langtemplate.file" value="${builddir}/files/langtemplate.txt" />

<!-- component test module properties -->
<property name="testsdir" value="./tests"/>
<property name="tests.srcdir" value="${testsdir}/src"/>
Expand Down
33 changes: 32 additions & 1 deletion componentbuild/shared/targets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@
<antcall target="-lint-server"/>
</target>

<!-- compiling handlebars templates if present -->
<target name="handlebars" description="Precompiles handlebars templates on /templates directory to js file">
<if>
<available file="${component.template.base}" type="dir" />
<then>
<echo level="verbose">Precompiling templates for ${component} </echo>
<fail>
<condition>
<not><resourcecontains resource="${component.basedir}/build.properties" substring="compiled-templates.js"/></not>
</condition>
Compiled templates not included in jsfiles!

ERROR:
The component ${component} uses templates, but
'${compiled-templates.file}' is not listed in the
'component.jsfiles' entry of 'build.properties'.

Please, add it to the file:
${component.basedir}/build.properties
</fail>

<compilehandlebars>
<sourcefiles>
<fileset dir="${component.template.base}" includes="${component.template.files}" />
</sourcefiles>
<outputfile>${component.jsfiles.base}/${compiled-templates.file}</outputfile>
</compilehandlebars>
</then>
</if>
</target>

<target name="-lint-server" description="Start JSLint Server" unless="lint.skip">
<antcall target="-node">
<param name="src" value="${builddir}/lib/jslint/jslint-node.js"/>
Expand Down Expand Up @@ -75,7 +106,7 @@
<delete dir="${component.builddir}" />
</target>

<target name="build" />
<target name="build" depends="handlebars" />

<!-- MIN -->
<target name="minify" description="Create component-min.js from component.js">
Expand Down