-
Posts
490 -
Joined
-
Last visited
-
Days Won
4
Everything posted by owzim
-
Hi, I'am at a loss ... I was absolutely certain that something like $wireData->has('key=value') or $wireData->is('key=value') existed. But it does not. has only takes a key name not a selector, and is does not exist on WireData. Is there another WireData method I am missing to accomplish this? I know there are simpler ways to get if a field has a certain value, but I need it as a selector string. Thanks!
-
Module Release: Blick - Helpers for your front end
owzim replied to owzim's topic in Modules/Plugins
@Mike Anthony I assume that people who use TemplateTwigReplace are already aware of that, but I probably should add that to the readme. Thanks. @renobird the version 2 days before the release was super simple too, I used it for months as it was. but then I thought: "If you're gonna release it, you should pimp it up a notch!" -
I investigated both approaches and went with @horst's suggestion on my Blick module. Although I think in the long run the whole image resize caching should be decoupled from the PageImage class, so that it can be used outside of page images. I'll elaborate more on that some other day, how that could be best accomplished, since it's not that easy and a lot of refactoring would be necessary.
- 5 replies
-
- images
- imagesizer
-
(and 1 more)
Tagged with:
-
Grand, thanks @Wanze I always think ProcessWire is so powerful and flexible, but that is also because PHP is so powerful and flexible, despite its fuglyness.
-
Thanks! Na, hooks are not a mystery to me but there are certain aspects, especially those under the hood (I am repeating myself ) that I still like to fully understand.
-
kongondo thanks, great to know that I really can reference the arguments by name, that is awesome. I still fail to understand how that works under the hood, I am always interested in that
-
A bit off topic, but I am curious Soma: How does the event know the argument names? I've found in the Wire class that when runHooks is called the HookEvent get's the arguments passed. Digging into the HookEvent class, I see that arguments can either be a numeric or an assoc array. So, I guess if I make a method in my Wire derived class hookable like so: public function ___foo($bar, $baz) {} When I hook into that method, I would NOT be able to get the arguments by name ($event->arguments('bar)), only by index ($event->arguments[0]), right? If not how would I DO make them able to be retrieved by name? If yes, is there some magic happening like stated here? Thanks
-
Ho did I miss that? Looks awesome, added it to my ever growing list of modules I definitely have to check out in depth.
-
No one has complained about issues, 1.0.0 it is. Merged into master, submitted to the directory and updated original post. I might not have the necessary time to tackle the road map for now, but if issues arise, I surely can fix them.
-
Interesting topic, thanks for your efforts accumulating all those infos. Although I've yet to investigate further the alternatives you are proposing, there are a couple of things that come to my mind regarding this: When it comes to debugging hooked methods, I totally feel you. It can make you pull your hair sometimes. But the thing is, you can either have massive flexibility and power in this case, and then have to trade in some other things. It's like with loosely types languages vs. strongly typed languages. Loosely typed languages give you great power, but it can be a pain, for let's say a Java developer. Two things I've used heavily in the past half year or so, that saved me a lot from going bald: The ChromePhpLogger module by soma, it's not an ideal debugging tool on it's own, but certainly a necessary one in my toolbox Unit tests: I've learned to split my logic into pieces as tiny as possible. During development I only test against those tiny pieces. If the pieces are working on their own, the big picture code will mostly work out of the box. Debugging also only happens on the tiny piece level and makes massive backtrace debugging madness almost vanish
-
Get it from GitHub Setup Just put the module in you modules directory and install it via admin. Intro This module might come in handy if you like to keep your templates clean and free of unreadable and unmaintainable string concatenations and even free of any logic. It also comes with some handy features besides just embedding JS, CSS and image assets, see below. Yikes! <link href="<?php echo $config->urls->templates . 'styles/foo.css'; ?>"> <link href="<?php echo $config->urls->templates . 'styles/bar.css'; ?>"> <script src="<?php echo $config->urls->templates . 'scripts/foo.js'; ?>"></script> <script src="<?php echo $config->urls->templates . 'scripts/bar.js'; ?>"></script> <img src="<?php echo $config->urls->templates . 'images/sky-scraper.jpg'; ?>" alt="Some huge building"> <img src="<?php echo $config->urls->templates . 'images/owzim.jpg'; ?>" alt="Handsome!"> Way cleaner <?php echo $asset->css('foo'); ?> <?php echo $asset->js('foo'); ?> <?php echo $asset->img('sky-scraper.jpg', 'Some huge building'); ?> or with short syntax <?= $asset->css('bar') ?> <?= $asset->js('bar') ?> <?= $asset->img('owzim.jpg', 'Handsome!') ?> And prettier if you're using Twig {{ asset.css('foo') }} {{ asset.css('bar') }} {{ asset.js('foo') }} {{ asset.js('bar') }} {{ asset.img('sky-scraper.jpg', 'Some huge building') }} {{ asset.img('owzim.jpg', 'Handsome!') }} Usage JS example Let's use the js method an its configuration as an example, and assume we have the following files located in /site/templates/scripts - index.js - index.min.js - main.js $config->blick = array( 'jsPath' => $config->paths->templates . 'scripts', 'jsUrl' => $config->urls->templates . 'scripts', 'jsMarkup' => '<script src="{url}"></script>', 'jsDefault' => 'markup', 'jsVersioning' => true, 'jsVersioningFormat' => '?v={version}', 'jsMin' => true, 'jsMinFormat' => "{file}.min.{ext}", ); $asset = $modules->get('Blick'); $asset->js('index')->url; // returns /site/templates/scripts/index.min.js?v=1426170460935 // 'min' and version parameter added, which was fetched from the file modified date $asset->js('main')->url; // returns /site/templates/scripts/main.js?v=1426170460935 // without 'min', because there is no main.min.js $asset->js('main'); // returns <script src="/site/templates/scripts/main.js"></script> // because 'jsDefault' is set to 'markup' // you can also access it explicitly via $asset->js('main')->markup $asset->js('http://code.jquery.com/jquery-2.1.3.js'); // returns <script src="http://code.jquery.com/jquery-2.1.3.js"></script> // nothing is modified here, because it's a remote url You can use the file name with or without extension. Adding a version parameter only takes place, if jsVersioning is set to true, it's a local file and it exists. Modifying the file name to include min only takes place, if jsMin is set to true, it's a local file and it exists. The same applies for the $asset->css('file') method: $config->blick = array( 'cssPath' => $config->paths->templates . 'styles', 'cssUrl' => $config->urls->templates . 'styles', // and so on ... ); IMG example the img method lets you include images, crop and resize them, without them having to be a page image. $config->blick = array( 'imgPath' => $config->paths->templates . 'images', 'imgUrl' => $config->urls->templates . 'images', 'imgMarkup' => '<img {attrs} src="{url}" alt="{0}">', 'imgDefault' => 'markup', 'imgVariationSubDir' => 'variations', ); $asset = $modules->get('Blick'); $asset->img('sky-scraper.jpg')->url; // returns /site/templates/images/sky-scraper.jpg $asset->img('sky-scraper.jpg', 'Some huge building'); // returns <img src="/site/templates/images/sky-scraper.jpg" alt="Some huge building"> // any arguments following the filename are passed as an array // in this case the alt value is the 0th argument, so {0} get's replaced // you can set as many arguments as you want in 'imgMarkup' $asset->img('sky-scraper.jpg')->size(100, 100)->url; // returns /site/templates/images/variations/sky-scraper.100x100.jpg // the resized image is put into a subdir 'variations' as configured in 'imgVariationSubDir' // if 'imgVariationSubDir' is left empty, the variation will be put in the same directory $asset->img('sky-scraper.jpg', 'Some huge building')->attr('title', 'Some huge building'); // returns <img title="Some huge building" src="/site/templates/images/sky-scraper.jpg" alt="Some huge building"> // the resized image is put into a subdir 'variations' as configured in 'imgVariationSubDir' // if 'imgVariationSubDir' is left empty, the variation will be put in the same directory You can also setup predefined variation settings in imgVariations $config->blick = array( 'imgVariations' => array( 'header' => array( 'width' => 960, 'height' => 360, 'options' => array( 'suffix' => 'header', ), ), 'person' => array( // and so on ... ), ), ); And call it like so: $asset->img('sky-scraper.jpg')->variant('header')->url; // returns /site/templates/images/variations/sky-scraper.960x360-header.jpg $asset->img('sky-scraper.jpg')->variant('header', 50)->url; // returns /site/templates/images/variations/sky-scraper.480x180-header.jpg Attributes example Since version 0.4.0 you don't need to create arbitrary variable placeholders, if you want to use attributes only. Now you can use the {attrs} placeholder and set the attributes via $asset->attr('name', 'value'). The name argument can also be multiple names, split by a pipe |. $config->blick = array( // ... 'imgMarkup' => '<img {attrs} src="{url}">', // ... ); $asset->img('sky-scraper.jpg')->attr('alt|title', 'Some huge building'); // returns <img alt="Some huge building" title="Some huge building" src="/site/templates/images/sky-scraper.jpg" > Using files that are not in the configured directory If you want to include files, that are neither in the configured directory nor in one of its sub directores, just use an absolute path (actually, relative to your /site directory. $asset->js($config->urls->SomeModule . 'scripts/file-in-root'); Autoload the module If you don't want to include the module manually via $assets = $modules->get('Blick'); you can set it to be autoloaded under a custom name: $config->blick['autoloadAs'] = 'fiddle'; Now it becomes automatically available in your templates under the name fiddle $fiddle->css('foo'); $fiddle->js('foo'); $fiddle->img('baz.png', 'qux'); Please note, that, if you're using the TemplateTwigReplace.module you will have to add your chosen autoload name to the Auto-import fuel list on the module's config page. See config-example.php for all configurable settings. Change Log 0.5.0 add optional scale argument to variant-method: $asset->img('foo.jpg')->variant('header', 50) 0.4.0 add possibility to get/set and render attributes (see section Attributes example) 0.3.0 add $asset->variant('name') alias for $asset->getVariation('name') 0.2.0 fixes and internal refactorings 0.1.0 initial version
- 8 replies
-
- 28
-
Haha, then again 5.3 is not even an officially supported PHP version anymore, so screw that =) Even 5.4 will be unsupported this year: http://php.net/supported-versions.php
-
LostKobrakai, I know but as long as PW supports 5.3.8 I'd like my modules to be compatible. If 5.4 is an official requirement, I can feel save making this a minimum for my modules as well.
-
Will there be a PHP version requirements bump to 5.4 in 2.6? I'd love to use short array notations in upcoming modules.
-
Thanks @horst, I will look into that.
- 5 replies
-
- images
- imagesizer
-
(and 1 more)
Tagged with:
-
Thanks @adrian, I will look into that.
- 5 replies
-
- images
- imagesizer
-
(and 1 more)
Tagged with:
-
I'd like to resize some images on demand, that are not page images, so they are not attached to a page. How to use the ImageSizer class? I could browse through the code but perhaps someone who used this, could provide some lines of example code. I basically want to pass the image path and cropping options. Are the cropped images saved somewhere if they are not page images, or will the cropping be executed every time? Thanks!
- 5 replies
-
- 2
-
- images
- imagesizer
-
(and 1 more)
Tagged with:
-
Awesome, can't wait to read it. Just bought the article online. btw. the article is called "Kurzer Prozess", literally translates to "short process", best English equivalent might be "to cut to the chase". Wordplay here.
-
Funny how all problems listed here annoyed me and others too, we get used to them and don't complain. That might even be dangerous, so client's feedback is key.
-
+1
-
I hope this kind of nasty and unmaintainable JS hacking when dealing with customization of behavior in admin (e.g. via modules) will not be necessary in the future. Proper standardization for PW JS stuff, like marginally discussed on this issue.
-
I've added and changed a lot of things on the dev branch. It'd be cool if you guys could test the current state to spot issues I have not encountered yet, so I can call it 1.0.0, merge it into master, and then publish it to the modules directory. Thanks! Changes, since the first post: 0.6.x - 0.12.x use noconflict version of ace implement possibility to add built-in extensions, by default emmet is enabled apply major PHP code refactoring 0.5.x enable field to be instantiated via API add interval check on editor.renderer.lineHeight and only initalize everything via callback when it is available add option to enable/disable localStorage make advancedOptions use the the Inputfield itself, INCEPTION! Regarding built-in extensions: They are sparsely documented, there are only two examples here. I have no idea what they all do. Some might even need additional libs, like emmet, which needs the core parser, that I included in this module.