Amadiere.com

Fourteen and a half crazy frog burpers

9th November 2009

BEHOLD! The coming of ASP.NET 4.0!

Filed under: ASP.NET, C#, MVC — Tags: , , — Alex Holt @ 8:30 pm

‘Tis a day of reconing upon us! The mighty that hath enjoyed the fruits of our labour shall become our lesser kin. ASP.NET#3.5 is being bumped up A WHOLE HALF VERSION! When you’ve regained your breath (have a cup of tea, if it helps) – read on for a breakdown of the glory that shall shine bright in all that is sparky, shiny and new!

First, for me, the major feature has to be something that is already available: ASP.NET MVC – now part of the ‘Out Of The Box’ experience and no longer required to be a separate download (though, still will be for ASP.NET 3.5). This in itself is worthy of a good cold shower, but get this… it’s version 2! Oh yeah, sweetness itself.

MVC 2.0 isn’t actually available as a release version at the moment and is in fact just a preview version. However, well worthy of look if you are at all interested in the original MVC. If you’ve been unable to see the new features in 2.0, then I seriously do not understand how you can sleep at night. In my bid to cure your insomnia, here are a few of the highlights, though, I could go on!

  • Areas are being introduced to allow you to easily spread your code apart into logical parts. E.g. You can have an area for your User / Account management stuff, and an area for your Product Listings. This allows you to keep the MVC pattern but in segmented way. Your User Area would have a directory for Controllers, Models and Views, and your Product Area would have separate areas too.
  • DataAnnotation Validation is voodoo. A black magic that makes you sit back and go: “WTF, is that it”? It allows you to declare the requirements of a field in a single place within your application, then any time something attempts to update it, the validation must be passed.
  • Default Values are easier to declare now.
    // something old
    public ActionResult Browse(string category, [DefaultValue(1)] int page)
    {
    }
    // something new
    public ActionResult Browse(string category, int page = 1)
    {
    }
  • They have shortened the attribute [HttpPost] . I know, I saved the best until last!
    // out with the old
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create(Product product)
    {
    }
    // in with the new!
    [HttpPost]
    public ActionResult Create(Product product)
    {
    }

As for the rest of ASP.NET 4.0, what can you look forward to? Well!

  • The superbly sweet…
    <%:productDescription%>

    Did you see it? The shorthand response.write alternative which was the equals sign has a rival. But not a dark nemesis with fire-breathing tentacles, nope, a bright white halo-toting angel rival. Simply replace the equal sign with a colon and you have a HTML Encoded Response.Write alternative. Finally, what seems to be a simple solution to reduce considerably, the risk of XSS attacks.

  • URL Routing (or of course, URL Rowwting if you are from the US) in much the same way that MVC has it. If you’re familiar with MVC 1, you’ll know the awesomeness that is the friendly URLs that they can produce. With ASP.NET4, this gesture is extended to the general Webforms environment.
  • Auto-Starting Web Applications are here! No longer do you need to set up a cron job to make sure that a random visitor doesn’t have to wait for 20 seconds while your application reloads itself into memory. A few tweaks and bliss is yours (and your customers).
  • Web.config has been on a diet. It’s shredded almost all of its weight. The only things that need to appear within this now are config settings that you actually want to change from their default. Genius!
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>
    </configuration>
  • The Entity Framework has become so awesome, it’s skipped a version or two to become EF4.0, and some of the upgrades make it strong and compelling contender for your model structuring! It contains considerably less suck than the first version.

All this ‘win’ makes you nervous? How can the world not implode? That my friend, I do not know – I think it may be like the Y2K Doomsday predictions – its the .NET4 DOOM! Either way, it’s looking good in the ASP.NET world at the moment and I can’t wait for it to land on my desktop!

5th November 2009

Quick Start Guide to Theming WordPress

Filed under: Web Design, Wordpress — Tags: , , — Alex Holt @ 8:01 pm

It’s taken a while, but I finally revamped the look of my site. Part of the problem, as always, is coming up with a design I can put up with for a while. I think that this red attempt should be OK for a while.

There a number of good WordPress theming guides out there (the one at WPDesigner.com is especially excellent) , so I don’t intend to replace them and their great detail. This post is merely some simple pointers for those that already know how to create HTML and understand enough about PHP to get by.

Create yourself a design! I’m totally gonna gloss over this part, despite being the major time consuming bit. I’m a big advocate of the multiple stage design process (Image -> HTML -> System Template). Basically – once you have a HTML / CSS version of what you want to achieve, its then time to work on how to get that into your WordPress Blog.

Create yourself a theme directory – this is within your /wp-content/themes directory and should make your theme sound totally awesome. Something like “Totally Rockin’ Monkey Burgers” should be sufficient.

Create your CSS file – Just copy your CSS file to your theme directory and make sure its named stylesheet.css You should also make sure you have something like the following in the top of it:

1
2
3
4
5
6
7
8
9
/*
Theme Name: Totally Rockin' Monkey Burgers
Theme URI: http://www.amadiere.com/blog/2009/11/quick-start-guide-to-theming-wordpress/
Description: Theme creation example.
Author: Alex Holt
Author URI: http://www.amadiere.com
Version: 1.0
Tags: red,white,fluid-fixed-width,two-columns
*/

Copy the PHP files from the Default theme – these act as a great starting point for your adaptations. You can now adapt these to pull together to create your style. They are split into 5 easy to comprehend areas by default. You don’t need to follow this however, you can simply put everything in one big file – though I find code becomes a lot more manageable when split over a few pages:

Index – the glue of the page, it calls the other templates where required. The key lines are:

<?php
get_header();
get_sidebar();
comments_template();
get_footer();
?>

Header – has the top part of your blog that is repeated throughout your site.

Footer – similar to the header, the code that appears at the foot of every page.

Sidebar – your navigation bar. For this, you effectively only need a small bit of code. The ‘dynamic_sidebar’ function calls all the Widgets that are enabled. This then basically generates a load of <li>’s, one for each Widget (these sometimes have nested UL’s and LI’s themselves):

1
2
3
4
5
6
7
<div id="navigation">
  <ul>
    <?php 	/* Widgetized sidebar, if you have the plugin installed. */
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) {}
    ?>
  </ul>
</div>

It is however worth mentioning that in circumstances that there are no Widgets – the above would output nothing but an empty unordered list.

Comments – Just displays the comments (if set to show), below each post. While there are a lot of bits in here, the main bit can be a touch hidden and is signified by a foreach loop within an Ordered List “commentlist”.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
<ol id="commentlist">
  <?php foreach ($comments as $comment) : ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
      <?php echo get_avatar( $comment, 80 ); ?>
      <div class="commentmeta">
        <?php comment_type(_x('Comment', 'noun'), __('Trackback'), __('Pingback')); ?>
        <?php _e('by'); ?> <?php comment_author_link() ?><?php comment_date() ?>
        @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a>
        <?php edit_comment_link(__("Edit This"), ' |'); ?>
      </div>
      <?php comment_text() ?>
    </li>
  <?php endforeach; ?>
</ol>

Create yourself a screenshot – it’ll make you feel good and will help you recognise the awesomeness that is your style when you are browsing through the hundreds you downloaded that are all tosh when compared with yours!

And that’s your lot.

As I mentioned, I don’t want to replace what is already out there on the web with this guide. In fact, I don’t the word ‘guide’ as it gets me quite excited and I expect something more dramatic than I’ve delivered. I think maybe prefixed with ‘Quick Start’ however, it might become acceptable… Yes. Yes, that seems not to have got my blood pumping!

Theme designed & built for Amadiere.com by Alex Holt. Powered by WordPress