Updates from August, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • danielsaidi 12:30 am on August 19, 2010 Permalink | Reply
    Tags: , bundle,   

    Bundle JavaScript and CSS files with full file paths 

    I have been looking at the great PHP CSS/JavaScript bundling approach that is presented at rakaz.nl. The suggested approach is great…and works great, but has a small drawback.

    The downloaded combine.php must be adjusted and all combined files must exist in the same folder.

    Not a big problem, I know, but since I have a structure where css/js files may exist in sub folders, I want to be able to provide the bundle URL with full paths to the files I want to bundle.

    Since the original solution is so slick, this is quite easy to achieve. I will not upload my solution for download, since I want you to grab the original code from rakaz.nl so that it receives the visitors it deserves 🙂

    Well, let’s get started:

    • In your project root, create a folder called bundle (or whatever you want, it is not that important)
    • In the bundle folder, create an .htaccess file and add the following code:
              RewriteEngine On
              RewriteBase /
              RewriteRule ^css/(.*\.css) /combine.php?type=css&files=$1
              RewriteRule ^javascript/(.*\.js) /combine.php?type=javascript&files=$1
    • In the bundle folder, create a combine.php file and add this content to it.

    Well, now you’re practically where the original approach tells you to adjust the PHP code a bit. Instead, do this:

    In the combine.php file, replace

              $path = realpath($base . '/' . $element);
    

    with:

              $path = "../" . $element

    The code has to be replaced at two places in the PHP file.

    That’s it!

    The only thing you have to consider now is to use application root relative paths when calling the bundle URL. This will cause your bundle URL to become quiiiite complex, but it works 🙂

    For instance, I have my main JavaScript folder in the application root folder content/js. Let’s say that I have the files a.js and b.js (great naming convention, ey?). The bundle URL would then be:

              bundle/javascript/content/js/a.js,content/js/b.js

    To bundle CSS files, the corresponding code would look like:

              bundle/css/content/css/a.css,content/css/b.css

    Well, you get the point 🙂

    The newly added code will add a ../ to each link before attempting to parse the file, which will work great since the combine.php file is placed one level down from the application root…to which the links have to be relative, remember?

    The great thing now is that I can bundle any JavaScript/CSS files (they still have to be bundled separately) regardless of their physical location (as long as they exist anywhere within the application root folder).

    Another great thing is that the .htaccess file is placed inside the bundle folder, which means that you can just copy the bundle folder if you want to use it in another project.

    Hope this helps!

     
  • danielsaidi 9:45 am on August 16, 2010 Permalink | Reply
    Tags: ,   

    Getting started with NDepend 

    I have just installed NDepend v3 Professional and will have a look at it. It seems to contain some cool features (and the integration with Visual Studio is slick) but I will look for some good tutorials that can help me get started.

    The features video that is available at the NDepend web site is quite thorough (although the voice seems to be generated), but if anyone has worked with NDepend v3, feel free to provide me with information about how to best make use of this seemingly great tool.

    Now, let’s analyze some previous code and find flaws that R# has missed 🙂

     
  • danielsaidi 9:35 pm on August 15, 2010 Permalink | Reply
    Tags: action, ,   

    Get the name of the current controller and action in ASP.NET MVC 

    I have been Googling my a** off to find how you get the name of the current controller and action. Eventually, I found this short, great page:

    http://w3mentor.com/learn/asp-dot-net-c-sharp/c-asp-net-mvc/get-name-of-current-controller-and-action-in-mvc/

    Not that straightforward…maybe time to create a small helper 🙂

     
    • torm 4:08 pm on January 5, 2011 Permalink | Reply

      Just curious – why would you need to check current controller ?

      • danielsaidi 9:09 am on January 11, 2011 Permalink | Reply

        When I wrote this post, I used the name of the current controller and action to highlight selected menu items.

  • danielsaidi 8:48 pm on August 12, 2010 Permalink | Reply
    Tags: , get_class, ini file, is_string   

    Getting familiar with PHP 5.3.2 

    Since I am no real PHP developer (just pretending), I have just started to use PHP 5.3.2., although PHP 5.3.3. was released a while back. The reason for this is that I’ve just installed Aptana Studio 2, which comes with 5.3.2.

    After installing Aptana Studio 2, I tried to execute a build/packagetest operation for my latest Wigbi version. It did not work, due to two small modifications in PHP 5.3.2.

    First of all, get_class does not accept string parameters anymore, so I’ll just have to change all the places where I use it. Thank GOD for TDD and all unit tests!

    I have used get_class in functions where a parameter could either be a string or an object. Instead, I now use is_string, which actually is a lot cleaner and…better.

    I’ve also noticed that the parse_ini_file function is a bit shaky. It is no longer able to parse ini files that end with a row at which a parameter is specified (like all my previous ini files). The file cannot be parsed, probably since the line feed is considered to be a part of the parameter value.

    I solve this by just adding an extra line after the last parameter. It’s a bit annoying, but I guess that the change is meant to make the function follow some kind of standard, so those extra lines are fine, I guess.

    After adjusting my code to these changes, everything ran smoothly once again.

     
  • danielsaidi 10:52 am on August 6, 2010 Permalink | Reply
    Tags: , div, float   

    The CSS fix of the day 

    Today, my dear collegue Johan Driessen showed me a nice CSS fix.

    The fix solves the problem that div elements with nested, floating divs will not resize according to the size of its nested elements, as such:

    Default div behavior

    Default div behavior: The div does not adjust its size according to nested, floating elements.

    Well, thanks to Johan  – although he stresses the fact that he found it on the web and did not write it himself – I have now a nice little CSS class that takes care of this:

       .fc:after{content:".";clear:both;display:block;visibility:hidden;height:0;}
       * html .fc{height:1px;}

    Just add this class to the div element that contains floating elements, and the result (sorry for the poooor graphics), will be as such:

    CSS fix result

    CSS fix: The div adjusts its size according to nested, floating elements.

    Hope this helps. If so, thank Johan.

     
  • danielsaidi 8:01 am on August 3, 2010 Permalink | Reply
    Tags:   

    Getting started with NDepend 

    I have been meaning to check out NDepend for quite some time, but now is finally the time to do so. Although I am excited to check out the new (well, fairly new) v3, I will start with actually reading…not so common these days 🙂

    This blog post by Patrick is a couple of years old, but the introduction that he mentions is, I believe, a good start to get an idea of the main features. After that, the new features of v3 will not be too far away. I will let you know how things progress.

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel