Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DSL to write Hudson's views with Ruby and ERB

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 pom.xml
Octocat-spinner-32 specs.watchr
README.textile

Hudson ERB plugin

Actually this is a Maven plugin to use to develop Hudson’s plugins and allows to write views with Ruby and ERB templates.

When we build a Hudson’s plugin with Maven it generates the jelly files that Hudson needs from our ERB templates.

WARNING: Right now it just includes a subset of the form views.

Configuration

Add this to the pom file:

  <build>
  ...
    <plugin>
        <groupId>org.mirah.hudson</groupId>
        <artifactId>hudson-erb-plugin</artifactId>
        <executions>
          <execution>
            <goals><goal>erb-compile</goal></goals>
          </execution>
        </executions>
      </plugin>

Usage

Add your ERB templates in the same place that you added your jelly files
with the same name but with extension jelly.erb, for instance if we have a
configuration form in src/main/resources/hudson/plugin/foo/config.jelly we
have to replace it with
src/main/resources/hudson/plugin/foo/config.jelly.erb.

Example

We can replace this code:

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
         xmlns:t="/lib/hudson" xmlns:f="/lib/form" >
  <f:entry name="Verbose" description="Show Mirah AST generation">
    <f:checkbox name="verbose" checked="${instance.verbose}"/>
  </f:entry>

  <f:entry name="Script" description="Mirah script">
    <f:textarea name="command" value="${instance.command}"/>
  </f:entry>
</j:jelly>

with this one:

<% view do %>
  <% entry 'Verbose', :description => 'Show Mirah AST generation' do %>
    <%= checkbox 'verbose' %>
  <% end %>

  <% entry 'Script', :description => 'Mirah script' do %>
    <%= textarea 'command' %>
  <% end %>
<% end %>

We can see this same example working in the Mirah Interpreter plugin

Extensions

In some cases perhaps we want to extend the dsl with our custom tags. We just need to create a file called ext.rb under the directory
src/main/resources/hudson_erb into our plugin and add the custom code to the module Hudson::View:

module Hudson
  module View
    def foo
      '<input type="foo"/>'
    end
  end
end

Then we can use that method in our views as we used any other:

  <% entry 'Foo', :description => 'My foo input' do %>
    <%= foo %>
  <% end %>
Something went wrong with that request. Please try again.