Module: Generators::Hobo
- Defined in:
- lib/generators/hobo/plugin.rb,
lib/generators/hobo/taglib.rb,
lib/generators/hobo/subsite.rb,
lib/generators/hobo/controller.rb,
lib/generators/hobo/invite_only.rb,
lib/generators/hobo/routes/router.rb,
lib/generators/hobo/activation_email.rb
Defined Under Namespace
Modules: Routes
Constant Summary collapse
- Plugin =
classy_module do protected def gem_with_comments(*args) = args. name = args[0] unless File.read("Gemfile") =~ /^gem ("|')#{name}/ if (comments = .delete(:comments)) append_file "Gemfile", "#{comments}", :verbose => false end gem(args[0], args[1], ) true else false end end def install_plugin_helper(name, git_path, ) plugin = name.dup unless [:skip_gem] = {} if git_path if git_path =~ /:/ [:git] = git_path else [:path] = git_path end end [:comments] = "# #{[:comments]}" if [:comments] need_update = gem_with_comments(plugin, [:version], ) end if [:subsite].nil? || [:subsite] == "all" subsites = ['front'] + ::Hobo.subsites else subsites = [[:subsite]] end subsites.each do |subsite| inject_js_require(name, subsite, [:comments]) unless [:skip_js] inject_css_require(name, subsite, [:comments]) unless [:skip_css] inject_dryml_include(name, subsite, [:comments]) unless [:skip_dryml] end return need_update end def inject_js_require(name, subsite, comments) application_file = "app/assets/javascripts/#{subsite}.js" pattern = /\/\/=(?!.*\/\/=).*?$/m unless exists?(application_file) application_file = "#{application_file}.coffee" pattern = /#=(?!.*#=).*?$/m end raise Thor::Error, "Couldn't find either #{subsite}.js or #{subsite}.js.coffee files!" unless exists?(application_file) inject_into_file application_file, :before=>pattern do line = "//= require #{name}\n" line = "//\n// #{comments}\n#{line}" if comments line end end def inject_css_require(name, subsite, comments) application_file = "app/assets/stylesheets/#{subsite}.scss" application_file = "app/assets/stylesheets/#{subsite}.css" unless exists?(application_file) raise Thor::Error, "Couldn't find #{subsite}.css!" unless exists?(application_file) opts = {:before => /\*=(?!.*\*=).*?$/m} raise Thor::Error, "Couldn't find #{subsite}.css!" unless exists?(application_file) inject_into_file application_file, opts do line = "*= require #{name}\n " line = "*\n * #{comments}\n #{line}" if comments line end end def inject_dryml_include(name, subsite, comments) subsite = "#{subsite}_site" unless subsite=="application" application_file = "app/views/taglibs/#{subsite}.dryml" pattern = /\<include gem=.*?\>(?!.*\<include gem=.*?\>).*?\n/m raise Thor::Error, "Couldn't find #{subsite}.dryml!" unless exists?(application_file) inject_into_file application_file, :after=>pattern do line = "\n<include gem='#{name}'/>\n" line = "\n<%# #{comments} %>#{line}" if comments line end end def exists?(file) File.exist?(File.join(destination_root, file)) end end
- Taglib =
classy_module do class_option :user_resource_name, :type => :string, :desc => "User Resource Name", :default => 'user' end
- Subsite =
classy_module do include Generators::Hobo::InviteOnly include Generators::Hobo::Taglib # check_class_collision :suffix => 'SiteController' def move_and_generate_files if can_mv_application_to_front_site? say "Renaming app/views/taglibs/application.dryml to app/views/taglibs/front_site.dryml" unless [:quiet] unless [:pretend] FileUtils.mv('app/views/taglibs/application.dryml', "app/views/taglibs/front_site.dryml") copy_file "application.dryml", 'app/views/taglibs/application.dryml' end end template "site.scss.erb", File.join('app/assets/stylesheets', "#{file_name}.scss") copy_file "gitkeep", "app/assets/stylesheets/#{file_name}/.gitkeep" template "site.js.erb", File.join('app/assets/javascripts', "#{file_name}.js") copy_file "gitkeep", "app/assets/javascripts/#{file_name}/.gitkeep" template "controller.rb.erb", File.join('app/controllers', file_name, "#{file_name}_site_controller.rb") application "#" application "config.assets.precompile += %w(#{file_name}.css #{file_name}.js)" application "# Hobo: the #{file_name} subsite loads #{file_name}.css & #{file_name}.js" end private def subsite_name class_name end def can_mv_application_to_front_site? File.exist?('app/views/taglibs/application.dryml') && !File.exist?('app/views/taglibs/front_site.dryml') end end
- Controller =
classy_module do # check_class_collision :suffix => 'Controller' class_option :helpers, :type => :boolean, :desc => "Generates helper files", :default => !Rails.application.config.hobo.dryml_only_templates def self. "rails generate hobo:controller #{self.arguments.map(&:usage).join(' ')}" end def generate_controller if class_path.length == 1 and subsite = class_path.first and ( [:subsite_controller_is_being_created] or File.exist?(File.join('app/controllers', class_path, "#{subsite}_site_controller.rb")) ) @subsite = subsite.camelize end template 'controller.rb.erb', File.join('app/controllers',"#{file_path}_controller.rb") end def generate_helper return unless [:helpers] invoke 'helper', [name], end end
- InviteOnly =
classy_module do class_option :invite_only, :aliases => '-i', :type => :boolean, :desc => "Add features for an invite only website" private def invite_only? [:invite_only] end end
- ActivationEmail =
classy_module do class_option :activation_email, :type => :boolean, :desc => "Send an email to activate the account" end