Browse Source

adding requirejs plugin integration tests.

main
Ilker Cetinkaya 12 years ago
committed by Lakshmi Vyasarajan
parent
commit
6c6a766415
7 changed files with 62 additions and 17 deletions
  1. +6
    -17
      hyde/ext/plugins/requirejs.py
  2. +1
    -0
      hyde/tests/ext/requirejs/app.js
  3. +3
    -0
      hyde/tests/ext/requirejs/lib/less.js
  4. +5
    -0
      hyde/tests/ext/requirejs/lib/more.js
  5. +3
    -0
      hyde/tests/ext/requirejs/main.js
  6. +6
    -0
      hyde/tests/ext/requirejs/rjs.conf
  7. +38
    -0
      hyde/tests/ext/test_requirejs.py

hyde/ext/plugins/rjs.py → hyde/ext/plugins/requirejs.py View File

@@ -11,9 +11,6 @@ import subprocess


class RequireJSPlugin(CLTransformer):
"""
The plugin class for requirejs
"""

def __init__(self, site):
super(RequireJSPlugin, self).__init__(site)
@@ -30,37 +27,29 @@ class RequireJSPlugin(CLTransformer):
Find the rjs conf file and set their relative deploy path.
"""
for resource in self.site.content.walk_resources():
if resource.source_file.name_without_extension == "rjs" and resource.source_file.kind == "conf":
if resource.source_file.name == "rjs.conf":
new_name = "app.js"
target_folder = File(resource.relative_deploy_path).parent
resource.relative_deploy_path = target_folder.child(new_name)

@property
def plugin_name(self):
"""
The name of the plugin.
"""
return "rjs"
return "requirejs"

def text_resource_complete(self, resource, text):
"""
Save the file to a temporary place and run less compiler.
Read the generated file and return the text as output.
Set the target path to have a css extension.
"""
if not resource.source_file.kind == 'conf' and not resource.source_file.name_without_extension == "rjs":
if not resource.source_file.name == 'rjs.conf':
return

rjs = self.app
target = File.make_temp('')
args = [unicode(rjs)]
args.extend(['-o'])
args.extend([unicode(resource)])
args.extend([("out=" + target.fully_expanded_path)])
args.extend(['-o', unicode(resource), ("out=" + target.fully_expanded_path)])

try:
self.call_app(args)
except subprocess.CalledProcessError:
raise self.template.exception_class(
"Cannot process %s. Error occurred when "
"processing [%s]" % (self.app.name, resource.source_file))

return target.read_all()

+ 1
- 0
hyde/tests/ext/requirejs/app.js View File

@@ -0,0 +1 @@
require(["lib/more"],function(e){return e("require")}),define("main",function(){});

+ 3
- 0
hyde/tests/ext/requirejs/lib/less.js View File

@@ -0,0 +1,3 @@
define(['lib/more'], function(more){
return more(s) + " or less";
});

+ 5
- 0
hyde/tests/ext/requirejs/lib/more.js View File

@@ -0,0 +1,5 @@
define(function(){
return function(s){
return s + " more";
};
});

+ 3
- 0
hyde/tests/ext/requirejs/main.js View File

@@ -0,0 +1,3 @@
require(['lib/more'], function(more){
return more("require");
});

+ 6
- 0
hyde/tests/ext/requirejs/rjs.conf View File

@@ -0,0 +1,6 @@
({
name: 'main',
include: ['lib/more'],
exclude: ['lib/less'],
logLevel: 3
})

+ 38
- 0
hyde/tests/ext/test_requirejs.py View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""
Use nose
`$ pip install nose`
`$ nosetests`
"""
from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.generator import Generator
from hyde.site import Site

RJS_SOURCE = File(__file__).parent.child_folder('requirejs')
TEST_SITE = File(__file__).parent.parent.child_folder('_test')

class TestRequireJS(object):
def setUp(self):
TEST_SITE.make()
TEST_SITE.parent.child_folder('sites/test_jinja').copy_contents_to(TEST_SITE)
RJS_SOURCE.copy_contents_to(TEST_SITE.child('content/media/js'))
File(TEST_SITE.child('content/media/js/app.js')).delete()

def tearDown(self):
TEST_SITE.delete()

def test_can_execute_rjs(self):
s = Site(TEST_SITE)
s.config.plugins = ['hyde.ext.plugins.requirejs.RequireJSPlugin']
source = TEST_SITE.child('content/media/js/rjs.conf')
target = File(Folder(s.config.deploy_root_path).child('media/js/app.js'))
gen = Generator(s)
gen.generate_resource_at_path(source)

assert target.exists
text = target.read_all()
expected_text = File(RJS_SOURCE.child('app.js')).read_all()

assert text == expected_text
return

||||||
x
 
000:0
Loading…
Cancel
Save