My goal is to use Twitter Bootstrap with my Symfony2 project. So, in my deps file I've added the following;
[twitter-bootstrap]
git=https://github.com/twitter/bootstrap.git
version=v1.4.0
...and ran bin/vendors install that downloads the library to the vendors directory. Now, I have no idea on how to include any of the assets in the parent twig template. Do I need to create a custom "Bundle" or is including the vendors lib simply good enough?
Probably, you are looking for this bundle. It does things you need.
Related
I have been reading about the new Asset Component. It seems very interesting and useful (as some people say :)). Since it seems it is not "recommended" to use Assetic any more, how should we filter .scss files to get .css files using this new component? I couldn't find any information about it..
Although Symfony 2.8 and later no longer includes Assetic by default, you can still install and enable it if you'd like to. (Basically: add symfony/assetic-bundle to your composer.json and add the necessary configuration.)
The best practice these days is to use frontend tools specifically focused for frontend development. (The Symfony best practices document specifically recommends GruntJS, but it's not the only solution.)
What do I use as the autoload file for my PHP Unit configuration file for my contributed bundle?
I'm writing unit tests for my first contributed Symfony 2 bundle. I'm not sure how to handle the XML configuration file phpunit.xml.dist for PHP Unit. I know I should write my own config file(instead of relying on the one provided by Symfony Framework), but I've seen a few different ways people handle the bootstrap file that the config uses.
Symfony framework apps have a PHP Unit config file in the app/ folder and it uses bootstrap.php.cache as the autoloader, which really just defers to the composer autoloader in the vendor directory.
Several bundles I've looked at have their own bootstrap file but try and locate some other autoload file on the filesystem, making assumptions about where it may be. That doesn't seem right to me, but perhaps it is?
The best practices don't get into specifics here.
Best practices for unit testing is to test a small unit of functionality at a time, this unit should not rely on external influences and doesn't make sense to use bootstrap.php.cache as that is intended to bootstrap the entire symfony framework.
Your tests within a bundle should be able to execute on their own if someone were to checkout your bundle and contribute to it, they should be able to run tests there with only your code and dependencies. An ideal scenario would be that no bootstrap is necessary to set up the test suite, all you need is the autoloader. This is why many bundles have a bootstrap script that loads the autoloader.
There are two scenarios on the autoloader location relative to the bundle, either your bundle is installed standalone and it will be in vendor/autoload.php or your bundle is installed as a dependency, which in a standard configuration would you would fall back to a project autoloader if that exists.
This is variable depending on your setup and usage of target dir... You would need to traverse upward at least two levels to account for vendor name and package name, then if you have a target directory configuration you would need to traverse upwards the number of directories in your target path.
I am working on a rails app and I would like to include some custom css files inside my rails application. I would like to separate out the css from bootstrap and the css that I wrote. Could I just put the custom css files inside vendor/assets/bower_components folder in my own css folder?
Is there anything else that I need to do for my css files to be picked up?
There are several ways you can achieve bower functionality in a Rails application.
Although having said that, I'm not sure about your wanting to use it on your custom.css file. The file itself will work just as well if you keep it in your app/assets/stylesheets folder, which will concatenate it to the asset pipeline
Bower-Rails
You'll may wish to consider using bower-rails, which seems to just give you the ability to use bower within your Rails app. This seems to be specifically for helping you keep your dependencies up to date:
Dependency file is bower.json in Rails root dir or Bowerfile if you
use DSL. Check out changelog for the latest changes and releases.
RailsAssets
Another amazing piece of functionality we found recently is "RailsAssets"
This works really well (we use it in production), as it keeps your dependent assets completely up to date. You can use it very simply:
#Gemfile
source https://rails-assets.org
gem 'rails-assets-BOWER_PACKAGE_NAME'
#app/assets/javascripts/application.js
//= require BOWER_PACKAGE_NAME
When running bundle update, this will then give you the ability to update your assets in line with your app!
I`m writing app that should work with twitter streaming api. For interacting with streaming api I use phirehose lib (https://github.com/fennb/phirehose). It runs great as separate php project. Php file with Phirehose lib is used as background process, that constantly consumes tweets, now I want save it in Db, so I need somehow make available all advantages work with DB of symfony framework in my simple php file that consumes tweets. Is there a way to make this, except put phirehose in vendor folder of symfony (I don't want to do this, cause in manuals that I find it is not easy, rename file and classes of lib, which can cause problems inside lib)?
This library is simple to use with composer. Just have a look at the composer.json file.
Add the following to your symfony composer.json then run composer update
"fennb/phirehose": "dev-master"
When extending the phirehose classes just do
class TwitterStuff extends \Phirehose
{
.........
As you know, in Symfony2.1 php bundles and packages are managed by composer, but would be maybe a good idea to hook up the managing of web assets as well? I would really love to update Twitter Bootstrap, jQuery, jQueryUi, Underscore.js and many other libraries using the same console command i use to update the php packages.
Are there any serious downsides of doing this?
Well, it sounds like a great idea, but I don't think it would be possible:
Composer is created for handling PHP dependencies, not for handling front-end dependencies, the twitter team has created Bower for front-end dependencies.
Combining those 2 great libraries is a huge task: You will need to create your own composer commands and configuration files.
Bower puts everything in a components directory. This isn't the correct dir for web assets, you will need to change this. You can't change this in the Bower config, as far as I know about Bower, which is almost equal to zero. UPDATE As said by #xanido, you can configure the output directory with the directory option as of Bower 0.3.0.
So well, you can manage web assets in Symfony2, with Bower (and maybe other programs like that), but combining those 2 isn't a good practise. Use Bower and Composer seperately can be useful, although you get another web assets directory.