Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[fixes #3] Add a config option to specify the RequireJS source URL

  • Loading branch information...
commit 68f4a779cbaaadd85a132d82aaa1b3a084cfc711 1 parent 15d65bd
@kmontag kmontag authored
View
3  DependencyInjection/Configuration.php
@@ -50,6 +50,9 @@ public function getConfigTreeBuilder()
->cannotBeEmpty()
->isRequired()
->end()
+ ->scalarNode('require_js_src')
+ ->defaultValue('//cdnjs.cloudflare.com/ajax/libs/require.js/1.0.5/require.min.js')
+ ->end()
->scalarNode('initialize_template')
->cannotBeEmpty()
->defaultValue('HearsayRequireJSBundle::initialize.html.twig')
View
2  DependencyInjection/HearsayRequireJSExtension.php
@@ -51,6 +51,8 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('hearsay_require_js.base_url', $config['base_url']);
$container->setParameter('hearsay_require_js.base_directory', $this->getRealPath($config['base_directory'], $container));
+ $container->setParameter('hearsay_require_js.require_js_src', $config['require_js_src']);
+
$container->setParameter('hearsay_require_js.initialize_template', $config['initialize_template']);
if (isset($config['optimizer'])) {
View
4 Resources/config/services.yml
@@ -21,7 +21,8 @@
parameters:
hearsay_require_js.base_url: js
- hearsay_require_js.base_directory: null # Set in the extension code
+ hearsay_require_js.base_directory: null # Set in the extension code
+ hearsay_require_js.require_js_src: null # Set in the extension code
hearsay_require_js.initialize_template: null # Set in the extension code
hearsay_require_js.r.path: null # Set in the extension code
@@ -70,6 +71,7 @@ services:
arguments:
- '@service_container'
- '@hearsay_require_js.configuration_builder'
+ - %hearsay_require_js.require_js_src%
tags:
- { name: twig.extension }
View
7 Resources/doc/index.rst
@@ -104,6 +104,13 @@ when initializing RequireJS::
</script>
{{ require_js_initialize({ 'configure' : false })
+To make global changes to the configuration/initialization output, you can
+specify an initialization template in your configuration::
+
+ # app/config/config.yml
+ hearsay_require_js:
+ initialize_template: '::initialize_require_js.html.twig'
+
Optimization
============
View
8 Resources/views/initialize.html.twig
@@ -34,9 +34,9 @@
{% endblock configuration %}
{% endif %}
-{% block requirejs %}
- {# Applications may override the requirejs_src block to use a custom URL. #}
- <script type='text/javascript'{% if main is defined and main is not empty %} data-main='{{ main }}'{% endif %} src='{% block requirejs_src '//cdnjs.cloudflare.com/ajax/libs/require.js/1.0.5/require.min.js' %}'></script>
-{% endblock requirejs %}
+{% block require_js %}
+ {# Applications may override the require_js_src block to use a custom URL. #}
+ <script type='text/javascript'{% if main is defined and main is not empty %} data-main='{{ main }}'{% endif %} src='{% block src require_js.src %}'></script>
+{% endblock require_js %}
{% endspaceless %}
View
11 Twig/Extension/RequireJSExtension.php
@@ -42,16 +42,24 @@ class RequireJSExtension extends \Twig_Extension
* @var ConfigurationBuilder
*/
protected $configurationBuilder = null;
+ /**
+ * @var string
+ */
+ protected $requireJsSrc = null;
/**
* Standard constructor.
* @param ContainerInterface $container Container to get the templating
* helper.
+ * @param ConfigurationBuilder $configurationBuilder For generating the
+ * initial Javascript config array.
+ * @param string $requireJsSrc Default URL to use for loading RequireJS.
*/
- public function __construct(ContainerInterface $container, ConfigurationBuilder $configurationBuilder)
+ public function __construct(ContainerInterface $container, ConfigurationBuilder $configurationBuilder, $requireJsSrc)
{
$this->container = $container;
$this->configurationBuilder = $configurationBuilder;
+ $this->requireJsSrc = $requireJsSrc;
}
/**
@@ -81,6 +89,7 @@ public function getGlobals()
return array(
'require_js' => array(
'config' => $this->configurationBuilder->getConfiguration(),
+ 'src' => $this->requireJsSrc,
),
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.