Wednesday, December 28, 2011

Moodle Timer Covering Quiz Question

When set to only show one question per page, Moodle's timer was covering up the start of the question - see below:

That pesky timer
Simple fix, based off an old suggestion from 2007 (http://moodle.org/mod/forum/discuss.php?d=45719), but updated to the new moodle 1.9.x code;

in /moode/mod/quiz/jstimer.php
 line 26 change width from 150 to 50
 line 29 change width from 150 to 50
 line 36 change font point size from 14 to 09
 line 51 change value of theTop from 100 to 25
And with that, the quiz now looks like:
Ah, fixed!

Tuesday, December 27, 2011

Basic Grails custom tag testing errors

You may encounter an error such as the following:

"No such property: out<or other method name> in package.classname "


This comes from writing the taglibtest like all the tutorials out on the web had said to, e.g. using:

class DateTagLib {
def thisYear = {
out << Calendar.getInstance().get(Calendar.YEAR)
'' //return empty text
 }
}

This problem arises from the newer versions of grails producing UNIT tests rather than INTEGRATION tests. In the unit environment, the Grails engine is not active to inject the dynamically created methods, such as validate, out.

So how do I resolve this? It runs just fine on the test webpage its included on. The test was failing when the tag clearly worked.



Three things to fix:

  1. Make sure your test case is extending TagLibUnitTestCase.
  2. Make sure you are calling super.setUp() in your test constructor
  3. Make a call to mockTagLib(YourTagClassHere) at the beginning of your test method.


So a basic test case for a custom tag (as shown above) might look like the following:


package yourpackage
import grails.test.*
class DateTagLibTests extends TagLibUnitTestCase  {
  def dateTagLib


  void setUp(){
 super.setUp()
 
    dateTagLib = new DateTagLib()

  }


  void testThisYear() {
 mockTagLib(DateTagLib)
    String expected = Calendar.getInstance().get(Calendar.YEAR)
    assertEquals("the years don't match", expected, dateTagLib.thisYear().toString())
  }
}

Wednesday, December 21, 2011

Changing syntax highlighting for Groovy/Grails in Eclipse

Looking for something a little easier on the eyes?
By combining the Eclipse color theme plugin with some specific groovy settings, you can make working with groovy much more 'visually' appealing.

1) Install the eclipse color theme plugin. Help->Eclipse Marketplace...->Search for "Eclipse Color Theme". Select a dark theme (or really any one of your choosing). You might notice some elements are not being colored correctly however, namely brackets and operators. To fix these last few elements we can manually change their color to something that suits.

2) Window->Preferences->Groovy->Editor. In this settings page you will find the rest of the settings you need to change. Set the operator, bracket colors to something more visible (and any other fine tweaks you may wish)

Enjoy!