Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bat-ria/tpl支持加载amd格式的模板文件 #17

Closed
leeight opened this issue Apr 26, 2014 · 6 comments
Closed

bat-ria/tpl支持加载amd格式的模板文件 #17

leeight opened this issue Apr 26, 2014 · 6 comments

Comments

@leeight
Copy link
Member

leeight commented Apr 26, 2014

--- a/dep/bat-ria/0.1.7/src/tpl.js
+++ b/dep/bat-ria/0.1.7/src/tpl.js
@@ -156,13 +156,18 @@ define(
                     require(dependencies, function () { load(text); });
                 }

-                var options = {
-                    method: 'GET',
-                    url: parentRequire.toUrl(resourceId),
-                    cache: true,
-                    dataType: 'text'
-                };
-                ajax.request(options).then(addTemplate);
+                if ( /html?/.test( resourceId ) ) {
+                    var options = {
+                        method: 'GET',
+                        url: parentRequire.toUrl(resourceId),
+                        cache: true,
+                        dataType: 'text'
+                    };
+                    ajax.request(options).then(addTemplate);
+                }
+                else {
+                    require( [ resourceId ], addTemplate );
+                }
@chestnutchen
Copy link
Member

上次在路上问过这个问题,这个还是要加上是吧?

@leeight
Copy link
Member Author

leeight commented Apr 28, 2014

cc @otakustay

@otakustay
Copy link
Member

嗯,不过我的计划是直接做成JSONP形式的用<script>引入~

@Justineo
Copy link
Member

<div>Template</div>

define(function() { return '<div>Template</div>'; });

@leeight 这么搞么?

@otakustay
Copy link
Member

require('etpl').parse('<div>Template</div>');

我原本是想搞成这样的,这还涉及到把原来的require全删了,似乎挺麻烦,还是搞成define算了

@leeight
Copy link
Member Author

leeight commented Apr 29, 2014

@leeight 这么搞么?

是的,TplMerge可以输出:

  1. <div>Template</div>
  2. define(function() { return '<div>Template</div>'; });

两种形式的代码,一个是普通的文本文件,一个是amd的模块

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants