Dynamically including taglibs. I deployed to production successfully. 
Therefore the concept is provem. So some minor bugs related to subsites 
corrected in the mean time. So here is the new code.

*config/application.rb*
    config.to_prepare do
      unless Rails.env.production?

        @loaded_include_tags_i ||= 0
        if Rails.const_defined? 'Server'
          load 'script/include_tags' if @loaded_include_tags_i.even?
          @loaded_include_tags_i += 1
        end
      end
    end
You can simply create new tag files, they'll be included on the next 
request. Why there is an odd even counter? File changes created by the 
script is refiring to_prepare and its entering a loop.

script/include_tags.rb
#!/usr/bin/env ruby

require 'pathname'

def subsite_tags(subsite)
  views_dir = 'app/views'
  
  if subsite == 'front'
    subsite_views_dir = views_dir
  else
    subsite_views_dir = File.join views_dir, subsite.to_s
  end
  
  tag_files = \
      Dir[ File.join subsite_views_dir, 'site_tags*/**/*.dryml' ]+ \
      Dir[ File.join subsite_views_dir, '*/view_tags*/**/*.dryml' ]
  tags = tag_files\
      .map{|f| 
           File.join File.dirname(f), File.basename(f, '.dryml')}\
      .map{|f|
          
 Pathname.new(f).relative_path_from(Pathname.new('app/views')).to_s }
  
  if subsite=='taglibs'
    library = 'application' 
  else
    library = subsite + '_site'
  end
  
  target = File.join(views_dir, 'taglibs', library +'_tags.dryml')
  
  File.open(target,'w') do |s|
    puts
    puts target
    puts '===='
    s.puts "<!-- ====  This is an auto generated file. Do not modify ==== 
-->"
    tags.each do |w|
      cmd = %Q{<include src="#{w}"/>}
      puts cmd
      s.puts cmd
    end
  end
  
end

subsite_tags('taglibs')
subsite_tags('front')
subsite_tags('admin') #Of course, if you have such a subsite
subsite_tags('accounting')  #Of course if you have such a subsite


Example site structure
app/views
    users
        index.dryml
        show.dryml
        view_tags
           card.dryml
           show.dryml
    site_tags
         social_share.dryml

     admin
         users
            view_tags
              form.dryml




-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to