# Humdrum humdrum is a collection of useful generators which are quite handy for starting up a project in ruby on rails. humdrum creates layouts using bootstrap, HTML5boilerplate etc to kick start a project. ## Installation Add this line to your application's Gemfile: gem 'humdrum' And then execute: $ bundle Or install it yourself as: $ gem install humdrum ## Usage ### STEP 1: Create the rails application $ rails new my_rails_app -m https://gist.githubusercontent.com/kpvarma/8fe9ed04092bb7868917/raw --skip-test-unit --skip-bundle The -m option will generate the application, download the template from the url mentioned and apply it to the generated output. Open the Gemfile once when the application is created and you will see the Gemfile having all the gems from the template Feel free to visit the URL https://gist.githubusercontent.com/kpvarma/8fe9ed04092bb7868917 to know how the template looks like. Checkout http://guides.rubyonrails.org/generators.html#generator-methods for knowing more about Rails Generators. ### STEP 2: Setup the project We now have a bare rails application. If you dont have bundler installed, first install it $ gem install bundler Lets bundle install which will download all the required gems $ bundle install ### STEP 3: Basic Humdrum Setup We will now see how humdrum can help us in setting up a project quickly. $ rails g humdrum:setup --config-database --dbase_name=my_rails_app --db_username=kpvarma --password=password1234 --rbenv_gemsets=my_rails_app rails g humdrum:setup Type **Y** for all the questions and you will see something like this: remove public/index.html create config/initializers/config_center.rb create config/locales/humdrum.en.yml create lib/core_ext/string.rb conflict .gitignore Overwrite /Users/kvarma/Projects/VarmaLabs/OpenSource/my_rails_app/.gitignore? (enter "h" for help) [Ynaqdh] Y force .gitignore create .ruby-version create .rbenv-gemsets create config/database.example.yml conflict config/database.yml Overwrite /Users/kvarma/Projects/VarmaLabs/OpenSource/my_rails_app/config/database.yml? (enter "h" for help) [Ynaqdh] Y force config/database.yml You will find more about these files and its usages in Wiki Section. As of now you just need to understand that humdrum:setup does the following: - removes the public/index.html for old rails application (This is not applicable for rails 4+) - creates a config_center.rb which is quite usefull to put all application constants. Open the file and check it out to understand what all things are there. - humdrum.en.yml is required by the controllers generated by humdrum for dealing with alerts and messages - string.rb has a useful mesthod is added to active record for randomly accessing elements from a table - .gitignore has a list of all the usefull file paths to be ignored by git - .ruby-version and -rbenv-gemsets helps us to manage ruby versions while dealing with a large number of projects - humdrum will generate database.yml with the options passed - checkout database.yml to understand better. - database.example.yml are required for deployment using capistrano. Ignore this if you are not dealing with deployment with capistrano. ### STEP 4: Create the database $ bundle exec rake db:create $ bundle exec rake db:migrate This should now create the required database ### STEP 4: Create a layout using humdrum $ bundle exec rails g humdrum:layout "user" --application-name="My Rails App" --fluid --framework=bootstrap3 -f This will create layouts compatible with bootstrap3 for quick start. This will also create a welcome page (landing page) which is linked as root url in routes.rb. You should see the following: force app/assets/stylesheets/application.css create app/assets/stylesheets/bootstrap.css create app/assets/stylesheets/overrides-bootstrap.css force app/assets/javascripts/application.js create app/assets/javascripts/validations/main.js create app/assets/javascripts/bootstrap.min.js create app/assets/javascripts/utilities.js create app/assets/images/favicon.ico create app/helpers/image_helper.rb create app/helpers/title_helper.rb create app/helpers/navigation_helper.rb create app/helpers/meta_tags_helper.rb create app/helpers/display_helper.rb create app/helpers/params_parser_helper.rb create app/helpers/flash_helper.rb force app/views/layouts/application.html.erb create app/views/layouts/application/_header.html.erb create app/views/layouts/application/_footer.html.erb create app/views/layouts/application/_navbar.html.erb create app/views/layouts/common/_flash_message.html.erb create app/views/layouts/common/_meta_tags.html.erb create app/views/layouts/common/_overlays.html.erb create app/views/layouts/user.html.erb create app/views/layouts/user/_header.html.erb create app/views/layouts/user/_footer.html.erb create app/views/layouts/user/_navbar.html.erb force app/controllers/application_controller.rb create app/controllers/welcome_controller.rb create app/controllers/user_controller.rb create app/views/welcome/index.html.erb create app/views/kaminari/_first_page.html.erb create app/views/kaminari/_gap.html.erb create app/views/kaminari/_last_page.html.erb create app/views/kaminari/_next_page.html.erb create app/views/kaminari/_page.html.erb create app/views/kaminari/_paginator.html.erb create app/views/kaminari/_prev_page.html.erb route root :to => 'welcome#index' Once again check your database.yml and ensure that the username and password is correct. Otherwise you are likely to see an error like this: "FATAL: role "xxxxxx" does not exist Run `$ bin/rake db:create db:migrate` to create your database" Once everything checked, start the rails server: $ rails s Take a browser and hit http://localhost:3000 and chekc out. ### STEP 5: Create a resource using humdrum $ rails g humdrum:resource users/document name:string --fluid --framework=bootstrap3 rails g humdrum:resource super_admin/admin name:string username:string status:string email:string phone:string address:string description:text password_digest:string auth_token:string --fluid --framework=bootstrap3 rails g humdrum:resource super_admin/trust name:string status:string email:string phone:string address:string description:text --fluid --framework=bootstrap3 rails g humdrum:resource admin/temple name:string description:text trust_id:integer --fluid --framework=bootstrap3 rails g humdrum:resource admin/deity name:string description:text temple_id:integer trust_id:integer --fluid --framework=bootstrap3 rails g humdrum:resource admin/offering name:string description:text temple_id:integer trust_id:integer --fluid --framework=bootstrap3 This will create layouts compatible with bootstrap3 for quick start. This will also create a welcome page (landing page) which is linked as root url in routes.rb. Once this is done, start the rails server, take a browser and hit http://localhost:3000 $ rails s http://localhost:3000 STEP LAST: Learn more about humdrum Now try rails g humdrum:setup --help rails g humdrum:layout --help rails g humdrum:resource --help rails g humdrum:api --help You will see the usage Possible Errors: When you run rails g humdrum:setup --help if you see 'Could not find generator humdrum:setup.' error you should go to Gemfile and ensure that you add humdrum to it gem "humdrum", "0.1.1" Humdrum also requires the following gems . so ensure that you have the latest ones. gem 'jquery-rails' gem 'jquery-validation-rails' gem "kaminari" gem "handy-css-rails", "0.0.4" You might want to add the following ones if you are using bootstrap framework gem "bootstrap-kaminari-views" gem "bootstrap-datepicker-rails" Setup rails g humdrum:setup --dbase="postgresql" --dbase_name="htb" --db_username="krishnan" db_password="password" --ruby_version="ruby-1.9.3-p429" --ruby_gemset="htb" This will create a ruby-version and ruby-gemset file. Also copies database.yml and database.example.yml (In a better format) No go back to parent folder and cd project_directory once again $ cd .. $ cd htb_app check rvm current you will see ruby-1.9.3-p429@htb now do bundle install again. Different usages rails g humdrum:setup rails g humdrum:setup -p rails g humdrum:setup --skip-gitignore -p rails g humdrum:setup --skip-gitignore -p rails g humdrum:setup --skip-gitignore --skip-ruby-gemset-p rails g humdrum:setup --skip-gitignore --skip-ruby-gemset -p rails g humdrum:setup --skip-gitignore --skip-gemset -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version --config-database -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version --config-database -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version -p rails g humdrum:setup --skip-gitignore --skip-gemset --skip-version --config-database -p rails g humdrum:setup --config-database --dbase="postgresql" --dbase_name="htb" --db_username="krishnan" db_password="password" --ruby_version="ruby-1.9.3-p429" --ruby_gemset="htb" -p Layout Create a basic layout including admin modules and user modules rails g humdrum:layout "HTB App" --create_admin_layout --create_user_layout -f skip welcome page rails g humdrum:layout "HTB App" --create_admin_layout --create_user_layout --skip_welcome_page -p Create a plain public layout to start with, including a landing page (welcome) rails g humdrum:layout "HTB App" Resource ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request 1. gem build humdrum-rails.gemspec 2. gem push humdrum-rails-0.1.0.gem