小编Sir*_*att的帖子

创建Gulp任务以缩小/连接文件以将来自多个目录的源打包到其各自目录中的文件中

我正在编写一个具有以下结构的Angular项目:

js/
    components/
        component1/
            component1.directive.js
            component1.controller.js
            component1.factory.js
            component1.rest.service.js
        component2/
            component2.factory.js
            component2.rest.service.js
    vendor/
        angular/
        jquery/
    home.js
    page2.js
Run Code Online (Sandbox Code Playgroud)

其中组件是共享资源,直接驻留在js /下的文件是所需组件和供应商库的包.

我想用gulp做的是创建一个任务,它将从每个组件目录中流式传输文件,监视更改以触发ngmin()和uglify(),然后将这些文件concat()转换为'{componentDirectoryName} .package.min生活在组件目录中的.js文件.结果看起来像这样:

js/
    components/
        component1/
            component1.directive.js
            component1.controller.js
            component1.factory.js
            component1.rest.service.js
            component1.package.min.js
        component2/
            component2.factory.js
            component2.rest.service.js
            component2.package.min.js
Run Code Online (Sandbox Code Playgroud)

目前的实施:

var gulp        = require('gulp');
var $           = require('gulp-load-plugins')({ camelize: true});
var glob        = require('glob');
var StreamQueue = require('streamqueue');

var publicDir = './src/main/webapp/public/';
var jsDir = publicDir + 'js/';
var components = jsDir + 'components/';

gulp.task('js', function() {
    var componentsDirectories = glob.sync(components + '/*/');
    var queue = new …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs gulp

7
推荐指数
1
解决办法
5839
查看次数

如何使用Sinon fakeTimer在Jasmine中测试LoDash去抖?

我正在尝试编写一个测试,用于在搜索查询中去除用户输入.该功能在骨干视图上定义:

SearchView = Backbone.View.extend({
    events: {
        "input .search-input": "search"
    },

    // init, render, etc.

    search: _.debounce(function() {
        this.collection.fetch();   
    }, 200)
});
Run Code Online (Sandbox Code Playgroud)

最初,Backbone库(v0.9.10)使用了Underscore(v1.4.4),测试定义如下:

describe("SearchView", function() {
    var view, $viewContainer;

    beforeEach(function() {
        appendSetFixtures('<div class="jasmine-container"></div>');
        $viewContainer = $(".jasmine-container");

        view = new SearchView({
            el: $viewContainer
        });
    });

    afterEach(function() {
        view.remove();
        view.cleanup();
    });

    //...

    describe("wires the search input", function() {
        var collectionStub,
            fakeTimer;

        beforeEach(function() {
            collectionStub = sinon.stub(
                SearchResultsCollection.prototype,
                "fetch"
            );     

            fakeTimer = sinon.useFakeTimers();
        });

        afterEach(function() { 
            collectionStub.restore();
            fakeTimer.restore();
        });

        it("should not trigger a search …
Run Code Online (Sandbox Code Playgroud)

backbone.js underscore.js jasmine sinon lodash

6
推荐指数
1
解决办法
4761
查看次数

无法将项目文件夹拖放到SimpleLESS Windows 7 64中

我已经下载了SimpleLESS来轻松编译和管理我的项目的LESS CSS文件.但是,安装后,我无法将任何文件夹拖放到拖放窗口中.有没有人在Windows 7 64位上成功使用SimpleLESS?我使用的LESS版本是1.4.

css less

5
推荐指数
1
解决办法
803
查看次数

将Grunt/Gulp和Livereload集成到服务于PHP/Zend的现有Apache服务器

我正在使用Zend框架开发一个PHP项目,该框架使用Apache在本地提供.是否有Grunt/Gulp的插件/配置允许我使用这个现有服务器并在我的phtml/php,CSS和JavaScript文件发生变化时重新加载我的浏览器?

javascript php apache gruntjs gulp

4
推荐指数
1
解决办法
5575
查看次数

使用Restangular协调Angular中的多个AJAX调用

我有一个Angular应用程序,其视图通过$ scope引用更新到工厂单例公开的某些模型和状态对象.在初始化期间或视图中的某些操作下,工厂必须进行多次AJAX调用(使用Restangular)并等待所有promises在更新其状态和模型属性之前得到解决.在对将来返回的数据应用适当的副作用之前,我该如何等待多个期货得到解决?

例如,显示加载微调器或模型属性的div,以及根据状态刷新此属性的按钮.

<div ng-controller="MyCtrl">
    <div ng-if="state.isLoading" class="loading-animation"></div>
    <div ng-if="!state.isLoading">
        <span ng-bind-template="Property: {{model.property}}"></span>
        <button ng-click="refresh()">Refresh</button>
    </div>    
</div>
Run Code Online (Sandbox Code Playgroud)
App.controller('MyCtrl', ['$scope', 'MyFactory', function('$scope', 'Factory') {
    $scope['model'] = Factory['model'];
    $scope['state'] = Factory['state'];
    $scope.refresh = function() {
        Factory.init();
    };
}])
.factory('MyFactory', ['restangular', function('Rest') {
    var Factory = {
            model = {
                property: null
            },
            state = {
                isLoading = false;
            }
        };

    Factory.init = function() {
        Factory['state']['isLoading'] = true;

        var promise1 = Rest.one('first').get();
            promise2 = Rest.one('second').get();

        // Resolve both promises.
        // Only when both …
Run Code Online (Sandbox Code Playgroud)

javascript ajax promise angularjs

3
推荐指数
1
解决办法
2815
查看次数

正则表达式匹配段落中的单词但排除内部HTML标记

我正在使用我在stackoverflow上找到的正则表达式来环绕带有span标记的段落中的单词实例,以便用户可以单击每个内部单词以查看该单词的定义.这完全有效,但是,我遇到的问题是,有时段落中包含内容或标签的单词短语,例如标题.

作品:

<div id="passage"> 
<p>
    Hello, my name is SirTophamHatt.
</p>
...
</div>

$('#passage').find('p').each(function() {
    $(this).html(function (index, oldHtml) {
        return oldHtml.replace(/\b(\w+?)\b/g, '<span class="word">$1</span>');
    });
});

<div id="passage">
<p>
    <span class="word">Hello</span>, <span class="word">my</span> <span class="word">name</span> <span class="word">is</span> <span class="word">SirTophamHatt</span>.
</p>
...
</div>
Run Code Online (Sandbox Code Playgroud)

不起作用:

<div id="passage"> 
<p>
    <em>Hello, my name is SirTophamHatt.</em>
</p>
...
</div>

$('#passage').find('p').each(function() {
    $(this).html(function (index, oldHtml) {
        return oldHtml.replace(/\b(\w+?)\b/g, '<span class="word">$1</span>');
    });
});

<div id="passage">
<p>
    <
    <span class="word">em</span>
    >
    <span class="word">Hello</span>, 
    <span class="word">my</span> 
    <span class="word">name</span> 
    <span class="word">is</span> …
Run Code Online (Sandbox Code Playgroud)

html javascript regex jquery

0
推荐指数
1
解决办法
4491
查看次数