GithubHelp home page GithubHelp logo

patgannon / blerg Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 92 KB

Blerg is designed to take the headache out of boilerplate code. Just write up an eRB template for the boilerplate and pass variables into it on the command line.

License: Apache License 2.0

Ruby 100.00%

blerg's Introduction

Blerg

Blerg is designed to take the headache out of boilerplate code. Just write up an ERB template for the boilerplate and pass variables into it on the command line.

Using

Blerg can be used directly from from the command line, or can be invoked by your own ruby scripts. The first step is to install the gem:

gem install blerg

Command line

Create an ERB template file for the boilerplate you'd like to generate, like the following:

class <%= @foo %> {
  public int id;
  public String name;

  public <% @foo %>(int id, String name) {
    this.id = id;
    this.name = name;
  }
}

Now run the blerg against your template, specifying the value you'd like to use for @foo (where mytemplate.erb is the file you created above)

blerg mytemplate.erb foo Bar

Blerg will execute the template, using the value "Bar" for the @foo variable (command-line variables are specified as sequences of key value pairs, like: key1 value1 key2 value2, etc.), and you would get the following

class Bar {
  public int id;
  public String name;

  public Bar(int id, String name) {
    this.id = id;
    this.name = name;
  }
}

In your ruby script

You can also invoke Blerg in your own ruby scripts, as in the following examples:

require 'rubygems'
require 'blerg'

generator = Blerg::Generator.new(:name => "Pat")
outputs = generator.generate(["Hello, my name is <%= @name %>"])

Calling Blerg in this way provides a bit more flexibility. You can invoke multiple templates using the same set of variables, and your templates don't need to be defined in a file.

Advanced Usage

Blerg depends on ActiveSupport, so you can use inflection methods like camelcase and underscore to handle common differences between naming conventions in DBs and those in programming languages, eg <%= @foo.underscore %>. For a list of all these methods, see: http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html

In ERB you can define variables, or even methods to make your templates as sophisticated as you'd like. You can read more about ERB here: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html

blerg's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.