46 lines
5.8 KiB
HTML
46 lines
5.8 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>core/frontend/helpers/index</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../../../"><meta name="groc-document-path" content="core/frontend/helpers/index"><meta name="groc-project-path" content="core/frontend/helpers/index.js"><link rel="stylesheet" type="text/css" media="all" href="../../../assets/style.css"><script type="text/javascript" src="../../../assets/behavior.js"></script><body><div id="meta"><div class="file-path">core/frontend/helpers/index.js</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
|
|
<span class="s2">"use strict"</span><span class="p">;</span>
|
|
|
|
<span class="kd">var</span> <span class="nx">_</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'underscore'</span><span class="p">),</span>
|
|
<span class="nx">moment</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'moment'</span><span class="p">),</span>
|
|
<span class="nx">coreHelpers</span><span class="p">;</span>
|
|
|
|
<span class="nx">coreHelpers</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">ghost</span><span class="p">)</span> <span class="p">{</span>
|
|
|
|
<span class="cm">/**</span>
|
|
<span class="cm"> * [ description]</span>
|
|
<span class="cm"> * @todo ghost core helpers + a way for themes to register them</span>
|
|
<span class="cm"> * @param {Object} context date object</span>
|
|
<span class="cm"> * @param {*} block</span>
|
|
<span class="cm"> * @return {Object} A Moment time / date object</span>
|
|
<span class="cm"> */</span>
|
|
<span class="nx">ghost</span><span class="p">.</span><span class="nx">registerThemeHelper</span><span class="p">(</span><span class="s1">'dateFormat'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">block</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="kd">var</span> <span class="nx">f</span> <span class="o">=</span> <span class="nx">block</span><span class="p">.</span><span class="nx">hash</span><span class="p">.</span><span class="nx">format</span> <span class="o">||</span> <span class="s2">"MMM Do, YYYY"</span><span class="p">;</span>
|
|
<span class="k">return</span> <span class="nx">moment</span><span class="p">(</span><span class="nx">context</span><span class="p">).</span><span class="nx">format</span><span class="p">(</span><span class="nx">f</span><span class="p">);</span>
|
|
<span class="p">});</span>
|
|
|
|
<span class="cm">/**</span>
|
|
<span class="cm"> * [ description]</span>
|
|
<span class="cm"> *</span>
|
|
<span class="cm"> * @param String key</span>
|
|
<span class="cm"> * @param String default translation</span>
|
|
<span class="cm"> * @param {Object} options</span>
|
|
<span class="cm"> * @return String A correctly internationalised string</span>
|
|
<span class="cm"> */</span>
|
|
<span class="nx">ghost</span><span class="p">.</span><span class="nx">registerThemeHelper</span><span class="p">(</span><span class="s1">'e'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">defaultString</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="kd">var</span> <span class="nx">output</span><span class="p">;</span>
|
|
|
|
<span class="k">if</span> <span class="p">(</span><span class="nx">ghost</span><span class="p">.</span><span class="nx">config</span><span class="p">().</span><span class="nx">defaultLang</span> <span class="o">===</span> <span class="s1">'en'</span> <span class="o">&&</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">hash</span><span class="p">)</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">ghost</span><span class="p">.</span><span class="nx">config</span><span class="p">().</span><span class="nx">forceI18n</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="nx">output</span> <span class="o">=</span> <span class="nx">defaultString</span><span class="p">;</span>
|
|
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
|
<span class="nx">output</span> <span class="o">=</span> <span class="nx">ghost</span><span class="p">.</span><span class="nx">polyglot</span><span class="p">().</span><span class="nx">t</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">hash</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
|
|
<span class="k">return</span> <span class="nx">output</span><span class="p">;</span>
|
|
<span class="p">});</span>
|
|
|
|
<span class="p">};</span>
|
|
|
|
|
|
<span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">.</span><span class="nx">loadCoreHelpers</span> <span class="o">=</span> <span class="nx">coreHelpers</span><span class="p">;</span>
|
|
<span class="p">}());</span></div></div></div></div></body></html> |