I'm just starting with Browserify and Gulp, and I'm having a little trouble covering all the bases that were previously covered by Grunt and Bower. Specifically, I can't get the two to work with Coffeeify. I could easily use a workflow where I convert the .coffee files to .js first, then bundle these files with Browserify; I am keeping around my "coffee" task anyway to check the resulting JavaScript source code. However, as I'm sure Coffeeify is already optimized for this task, I would rather use that instead.
I am getting "Error: write after end" whenever I try to transform the bundle with Coffeeify. I have tried omitting the extension and specifying it in Browserify's options; using Browserify's built-in "transform" option (commented out here), which isn't present in Browserify's API docs but which I saw in some StackOverflow questions; and using Browserify's ".add()" function (also commented out here), but nothing seems to work. I have tried using coffeeify as a function, with quotes and without quotes.
I am having trouble searching, probably because Browserify's API is in early stages and therefore changing a lot. I have successfully used Coffeeify from the command line, in the way specified in the GitHub repo.
var gulp = require('gulp');
var rename = require('gulp-rename');
var browserify = require('browserify');
var coffeeify = require('coffeeify');
var transform = require('vinyl-transform');
gulp.task('browserify', function() {
return gulp.src('app/modules/main/coffee/app.coffee', {base: './'})
.pipe(transform(function(filename) {
return browserify({
entries: filename,
debug: true,
// transform: ['coffeeify'],
extensions: ['.coffee']
})
// .add(filename)
.transform('coffeeify')
.bundle();
}))
.pipe(rename(function(path) {
path.dirname = '',
path.basename = 'index',
path.ext = '.js'
}))
.pipe(gulp.dest(''));
});
Am I missing something silly? Does Coffeeify not work with vinyl-transform, and should I use vinyl-source-stream instead? Do I have the order wrong? Why isn't Coffeeify working in my Gulp task?
I have not used coffeeify, so this may not apply, but when I was running some shell commands, the return command in gulp was trying to execute before all of the shell commands were finished. It was like the first shell command returned good, so gulp tried to move on, and then the second shell command tried to return and gulp said no.
try this...
var gulp = require('gulp');
var rename = require('gulp-rename');
var browserify = require('browserify');
var coffeeify = require('coffeeify');
var transform = require('vinyl-transform');
gulp.task('browserify', function() {
gulp.src('app/modules/main/coffee/app.coffee', {base: './'})
.pipe(transform(function(filename) {
return browserify({
entries: filename,
debug: true,
// transform: ['coffeeify'],
extensions: ['.coffee']
})
// .add(filename)
.transform('coffeeify')
.bundle();
}))
.pipe(rename(function(path) {
path.dirname = '',
path.basename = 'index',
path.ext = '.js'
}))
.pipe(gulp.dest(''));
return gulp.src('');
});
Here's an abridged version of what I'm doing in my Browserify Gulp task. Note that I'm using gulp-browserify instead of browserify.
gulp = require 'gulp'
concat = require 'gulp-concat'
browserify = require 'gulp-browserify'
gulp.task 'coffee', ->
gulp.src( '_assets/js/src/**/*.coffee', read: false )
.pipe browserify( transform: ['coffeeify'], extensions: ['.coffee'] )
.pipe concat( 'app.js' )
.pipe gulp.dest( '_assets/js/dist/' )
You probably don't need the concat() since you're only processing one file, so the equivalent JS for your specific case would probably look something like this:
var gulp = require( 'gulp' );
var rename = require( 'gulp-rename' );
var browserify = require( 'gulp-browserify' );
gulp.task( 'browserify', function() {
return gulp.src( 'app/modules/main/coffee/app.coffee', { read: false, base: './' } )
.pipe( browserify( {
debug: true,
transform: ['coffeeify'],
extensions: ['.coffee']
} ) )
.pipe( rename( {
dirname: '',
basename: 'index',
extname: '.js'
} ) )
.pipe( gulp.dest( '' ) );
} );
An alternative method where you continue to use the base browserify package would be:
var gulp = require( 'gulp' );
var source = require( 'vinyl-source-stream' );
var browserify = require( 'browserify' );
gulp.task( 'browserify', function() {
return browserify( {
debug: true,
entries: ['app/modules/main/coffee/app.coffee'],
transform: ['coffeeify'],
extensions: ['.coffee']
} )
.bundle()
.pipe( source( 'index.js' ) )
.pipe( gulp.dest( './' ) );
} );
I haven't tested any of this but hopefully one of those two examples will work for you, or at least point you in the right direction.
Related
I made a photobooth with Dancer some years ago and it worked fine.
Now I try to move this to Dancer2. However, It's not working anymore, because I have some infinite-loop.
Let's say my app looks like this:
package App;
use Dancer2;
# Photobox is my pm file with all the magic
use Photobox;
my $photobox = photobox->new();
get '/photo' => sub {
my $photo;
# Trigger cam and download photo. It returns me the filename of the photo.
$photo = $photobox->takePicture();
# Template photo is to show the photo
template 'photo',
{
'photo_filename' => $photo,
'redirect_uri' => "someURI"
};
}
takePicture() looks like this:
sub takePicture {
my $Objekt = shift;
my $return;
my $capture;
$return = `gphoto2 --auto-detect`;
if ($return =~ m/usb:/) {
$capture = `gphoto2 --capture-image-and-download --filename=$photoPath$filename`;
if (!-e $photoPath.$filename) {
return "no-photo-error.png";
}
else {
return $filename;
}
} else {
die "Camera not found: $return";
}
}
When I now call /photo, it'll result in an infinite loop. The browser is "frefreshing" all the time and my cam is shooting one photo after the other. But it never redirects to /showphoto.
It was working with Dancer(1) when I run the application just by perl app.pl from the bin directory. How I use Dancer2 und run it by using plackup app.psgi
I tried to put it into a before hook, but it changed nothing.
Update:
I figured out a way to work around this issue.
First I refactored my code a bit. Basic idea was to split the take photo and show photo operations into two different routes. This makes it easier to see what happens.
get '/takesinglephoto' => sub {
my $photo;
$photo = takePicture();
$single_photo=$photo;
redirect '/showsinglephoto';
;
get '/showsinglephoto' => sub {
set 'layout' => 'fotobox-main';
template 'fotobox_fotostrip',
{
'foto_filename' => $single_photo,
'redirect_uri' => "fotostrip",
'timer' => $timer,
'number' => 'blank'
};
};
And I moved the takePicture method just into my Dancer main App.pm.
Now I recognized from the log output, that the browser does not load the '/takesinglephoto' page once, but refreshes it every some secons. I think the reason is, that takePicture() takes some seconds to run and to return the output. And Dancer does not wait until it ends. With every reload, it triggers the takePicture() again and that causes the infinite-loop.
I worked around this by implementing a simple check to run takePicture() just once.
# define avariable set to 1 / true
my $do_stuff_once = 1;
get '/takesinglephoto' => sub {
my $photo;
# check if variable is true
if ($do_stuff_once == 1) {
$photo = takePicture();
$single_photo=$photo;
# set variable to false
$do_stuff_once = 0;
}
redirect '/showsinglephoto';
};
get '/showsinglephoto' => sub {
# set variable back to true
$do_stuff_once = 1;
set 'layout' => 'fotobox-main';
template 'fotobox_fotostrip',
{
'foto_filename' => $single_photo,
'redirect_uri' => "fotostrip",
'timer' => $timer,
'number' => 'blank'
};
};
Now it still refreshes /takesinglephoto, but it does not trigger takePicture() again and again and finally, when the method returns the photo filename, it redirects to /showsinglephoto.
I would call this a workaround. Is there a better way to solve this?
BR
Arne
Can anyone let me know how can I change the default download location for Chrome using Selenium-Perl. I am using Chrome Webdriver and the Perl module Selenium::Remote::Driver. I got code for Java but not in Perl for this task.
I do not have the test setup but passing below as desired_capabilities or extra_capabilities to the constructor should work fine.
'download.default_directory', 'C:\New_Folder'
Snippet (untested):
my $driver = Selenium::Remote::Driver->new(
'browser_name' =>'chrome',
'extra_capabilities' => {
'chromeOptions' => {
'prefs' => {
'download.default_directory' => 'C:\New_Folder'
}
}
}
);
Edit: Difference between Selenium::Chrome and Selenium::Remote::Driver
Selenium::Chrome allows you to use the ChromeDriver without needing the JRE or a selenium server running. If the ChromeDriver binary is not found, it falls back to the default Selenium::Remote::Driver.
I had troubles understanding the difference mentioned between Selenium::Chrome and Selenium::Remote::Driver. Here's what I got to work:
my $driver = Selenium::Chrome->new(
extra_capabilities => {
'goog:chromeOptions' => {
prefs => {
'download.default_directory' => '/tmp'
},
args => [ 'window-size=1950,500' ]
}
}
);
I want to know how to create a ckeditor(v4.x) plugin with two or more commands inside it.
I'm able to create and execute a ckeditor with one command, as the code can be saw below:
CKEDITOR.plugins.add ('family',
{
init: function (editor)
{
editor.setKeystroke (CKEDITOR.CTRL + 65, 'parent'); // CTRL+A
editor.addCommand ('parent',
{
exec : function(editor)
{
var selection = editor.getSelection ().getSelectedText ();
editor.insertHtml ('<span data-role="parent">' + selection + '</span>' );
}
});
}
} );
What I want to achieve:
CKEDITOR.plugins.add ('family',
{
init: function (editor)
{
editor.setKeystroke (CKEDITOR.CTRL + 65, 'parent'); // CTRL+A
editor.addCommand ('parent',
{
exec : function(editor)
{
var selection = editor.getSelection ().getSelectedText ();
editor.insertHtml ('<span data-role="parent">' + selection + '</span>' );
}
});
editor.setKeystroke (CKEDITOR.CTRL + 69, 'child'); // CTRL+E
editor.addCommand ('child',
{
exec : function (editor)
{
var selection = editor.getSelection ().getSelectedText ();
editor.insertHtml ('<span data-role="child">' + selection + '</span>' );
}
});
}
} );
Suggestions?
I made a mistake in my tests to verify if the plugin was or not working. The mistake made it looks like it wasn't when it was.
This way of inserting two commands to one plugin does really work.
In this test I am unsure why you need to set the angular variable to the injection params in these 2 lines. Is it because the injection doesn't automatically assign the $compile and $rootScope?
$compile = $c;
$rootScope = $r;
from
describe("Unit: Testing Directives", function() {
var $compile, $rootScope;
beforeEach(module('App'));
beforeEach(inject(
['$compile','$rootScope', function($c, $r) {
$compile = $c;
$rootScope = $r;
}]
));
it("should display the welcome text properly", function() {
var element = $compile('<div data-app-welcome>User</div>')($rootScope);
expect(element.html()).to.match(/Welcome/i);
})
});
Try something like this it works for me:
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
$scope = $rootScope.$new();
$http = $injector.get('$http');
$q = $injector.get('$q');
}));
I have been trying to set up an app through PhoneGap (Cordova) to take images and upload them to our server. I have gone through so many of the responses on here and tried the code in them. I can get the camera up and taking a photo, I can access the phone gallery even. But I can not get it to send the image to the server. I've tried sending the image, and even sending the base64 image stream. I can't get it to the server.
Here is the javascript on the client side:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
}
function ImageUpload() {
this.useExistingPhoto = function(e) {
this.capture(Camera.PictureSourceType.SAVEDPHOTOALBUM);
}
this.takePhoto = function(e) {
this.capture(Camera.PictureSourceType.CAMERA);
}
this.capture = function(sourceType) {
navigator.camera.getPicture(this.onCaptureSuccess, this.onCaptureFaile, {
destinationType: Camera.DestinationType.FILE_URI,
soureType: sourceType,
correctOrientation: true
});
}
this.onCaptureSuccess = function(imageURI) {
var fail, ft, options, params, win;
success = function(response) {
alert("Your photo has been uploaded!");
};
fail = function(error) {
alert("An error has occurred: Code = " + error.code + "\nMessage = "+error.message);
};
options = new FailUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "text/plain";
params = {
val1: "some value",
val2: "some other value"
};
options.params = params;
ft= new FileTransfer();
ft.upload(imageURI, 'http://style.appdev01.com/app/client-profile.php', success, faile, options);
}
this.OnCaptureFail = function(message) {
alert("Failed because: "+message);
}
};
var imageuploader = new ImageUpload();
Two buttons call imageuploader.takePhoto and .useExistingPhoto on click.
On the server side I have this php:
if(isset($_FILES['file'])) {
$target_path = "/home/style/public_html/images/client_images/app_image.jpg";
move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
$insert = "INSERT INTO
`fut`
SET
`request` = '".serialize($_POST)."',
`file` = '".serialize($_FILES)."'";
$mysql->query($insert);
}
This is just to store the POST and FILE arrays to the db to make sure they came through and create the image.
But again, nothing is getting to the server. Any help would be GREATLY appreciated. I've tried so many versions of this code from so many questions here and all over the web.
define ('SITE_ROOT', realpath(dirname(__FILE__))); /* echo SITE_ROOT; to dir
move_uploaded_file($_FILES["file"]["tmp_name"],SITE_ROOT."/uploads/".$_FILES["file"]["name"]); // will move file, make sure uplaods has write permission!
That works for me on Android Simulator, not on Tablet, but let me know if you have it working, busy on the same thing.
$myarray = array( $_REQUEST);
foreach ($myarray as $key => $value) {
echo "<p>".$key."</p>";
echo "<p>".$value."</p>";
echo "<hr />";
}
That you can use to check POST / GET!
Try this is my code. It has worked for me.
Encode your URL by encodeURI method
fileKey with "file" as in your server side script $_FILES['file']
uploadFile: function(refNo){
var uri = fileUpload.fileUri;
var file = uri.substr(uri.lastIndexOf('/') + 1);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = file;
options.mimeType="image/jpeg";
alert("name === "+uri);
options.chunkedMode = false;
var ft = new FileTransfer();
Common.ajaxLoading('show');
ft.upload(uri,encodeURI("http://172.16.1.147:80/upload/home.php") , fileUpload.uploadSuccess, fileUpload.uploadFail, options, true);
},