Giter Club home page Giter Club logo

rails3_assist's Introduction

Rails3 Assistant

Includes various helpers to assist operating on a Rails 3 application.

Install

gem install rails3_assist

File Assistants

There are file assistants for the following Rails 3 artifacts:

  • locale

  • javascript

  • stylesheet

  • controller

  • helper

  • view

  • model

  • mailer

  • observer

  • permit

  • view

  • [name]_file

  • [name]_files

  • create_[name]_file

  • remove_[name]_file

  • remove_all__[name]s

  • remove_[name]s

Example usage:

remove_locales 'blip.en', 'blip.dk'	
remove_all_stylesheets
create_stylesheet 'my_styles.css' do
 %{
  .mystyle {font: bold;}	
}
end
remove_stylesheet 'my_styles.css'	
	
locale_files
locale_files 'permit.dk'
locale_files /permit/ do |files|
  # ...
end

view_files :person 
erb_view_files(:user).file_names.should include 'show.html.erb'
haml_view_files(:user)

Directory Assistants

There are dir helpers for the following

  • app

  • config

  • db

  • public

  • lib

  • log

  • doc

  • test

  • spec

  • locale

  • initializer

  • javascript

  • stylesheet

  • controller

  • helper

  • view

  • model

  • mailer

  • observer

  • permit

  • view

Example usage:

	config_dir
	observer_dir_
	db_dir :root_path => MY_RAILS_ROOT
	rails_dir_for :migrations
	db_dir_for :migrations	
	config_dir_for :initializers, :root_path => MY_RAILS_ROOT
	app_dir_for :models

Special Rails mutators

  • insert_application_config
  • insert_before_application_init
  • insert_after_application_init

Special file helpers:

  • application_file

  • environment_file

  • seed_file

  • read_[special]_file

  • remove_[special]_file

  • append_to_[special]_file

  • replace_in_[special]_file :where => ... :with => ...

  • remove_from_[special]_file

Example

remove_from_application_file /config.root = (\w+?)/ 
append_to_seed_file do
  %{
  Person.new :name => 'Mike'
}
end

Usage

Set the root if not already set, then use the special assist methods to include the modules with all the goodies! See the Assistants section below for more info on how to do this.

Rails root

You have to set the class variable Rails::Assist::Directory.rails_root to the location of your Rails root directory if you are using this gem outside of Rails, fx for testing purposes or something.

Note: If this variable is not set, it will assume it is used in a Rails app and therefore assume the root is Rails.root.

In the specs of this projct, I use the rails_root class variable to avoid having to set a Rails app specific variable, which I deemed unnecessary for most of the tests.

Assistants

Generators are often designed to create Rails 3 artifacts or update existing artifacts. It's often useful to include one or more Rails 3 artifact assistants along with a generator assistant (see above).

This combination greatly facilitates your work in developing the generator, as much of the heavy lifting will be done for you in the assistants.

To use a specific assistant/helper, simply call:

assist_with [list of assistant symbols]

Example:

assist_with :controller, :model, :view, :permit

Aliases: use_helpers and use_helper

Available helpers:

Artifacts

  • controller
  • model
  • view
  • helper
  • observer
  • mailer
  • migration
  • permit

Misc.

  • file
  • files
  • directory

Using Assistants

	
class MyGenerator < Rails::Generators:NamedBase
  extend Rails3::Assist::UseMacro

  use_orm :active_record
  use_helpers :file, :files, :controller, :observer, :migration
  ...
end

Assistant in RSpec

The assistants are preconfigured to be available within RSpec constructs.

	
describe 'My Controller' do
  use_helpers :directory, :files, :helper, :mailer
  ...
end

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.

rails3_assist's People

Contributors

kristianmandrup avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.