解决CommunityEngine在windows下部署时候样式丢失的问题

CommunityEngine 是Rails下一个相当不错的社会化网络插件。

在linux下测试使用时候,相当的顺利,但在Windows下使用时,且在启动的时候出现以下错误,虽然可以正常启动,却发现样式全没了。

  1. Attempting to copy plugin assets from 'E:/workspace/beeblio/vendor/plugins/community_engine/assets' to 'E:/workspace/beeblio/public/plugin_assets'
  2. WARNING: Couldn't create the public file structure for plugin 'community_engine'; Error follows:
  3. Invalid argument - E:/workspace/beeblio/public/plugin_assets/community_engine/E:
  4. Attempting to copy plugin assets from 'E:/workspace/beeblio/vendor/plugins/community_engine/engine_plugins/tiny_mce/public' to 'E:/workspace/beeblio/public/plugin_assets'
  5. WARNING: Couldn't create the public file structure for plugin 'tiny_mce'; Error follows:
  6. Invalid argument - E:/workspace/beeblio/public/plugin_assets/tiny_mce/E:
  7. checking plugin 'engines' for 'application_helper'
  8. checking plugin 'community_engine' for 'application_helper'

折腾半天,后来,发现,其实这根本不是CE的问题,而是CE用到的另一个插件Engine的bug

解决办法是:

打开Vendor/plugins/engines/lib/engines.rb

把第148行         #FileUtils.mkdir_p(base_target_dir) 调整为 FileUtils.mkdir_p(destination)

再次启动CE,发现,样式全回来了,SO cool。

  1. require 'active_support'
  2. require File.join(File.dirname(__FILE__), 'engines/plugin')
  3. require File.join(File.dirname(__FILE__), 'engines/plugin/list')
  4. require File.join(File.dirname(__FILE__), 'engines/plugin/loader')
  5. require File.join(File.dirname(__FILE__), 'engines/plugin/locator')
  6. require File.join(File.dirname(__FILE__), 'engines/assets')
  7. require File.join(File.dirname(__FILE__), 'engines/rails_extensions/rails')
  8. # == Parameters
  9. #
  10. # The Engines module has a number of public configuration parameters:
  11. #
  12. # [+public_directory+]  The directory into which plugin assets should be
  13. #                       mirrored. Defaults to <tt>RAILS_ROOT/public/plugin_assets</tt>.
  14. # [+schema_info_table+] The table to use when storing plugin migration 
  15. #                       version information. Defaults to +plugin_schema_info+.
  16. #
  17. # Additionally, there are a few flags which control the behaviour of
  18. # some of the features the engines plugin adds to Rails:
  19. #
  20. # [+disable_application_view_loading+] A boolean flag determining whether
  21. #                                      or not views should be loaded from 
  22. #                                      the main <tt>app/views</tt> directory.
  23. #                                      Defaults to false; probably only 
  24. #                                      useful when testing your plugin.
  25. # [+disable_application_code_loading+] A boolean flag determining whether
  26. #                                      or not to load controllers/helpers 
  27. #                                      from the main +app+ directory,
  28. #                                      if corresponding code exists within 
  29. #                                      a plugin. Defaults to false; again, 
  30. #                                      probably only useful when testing 
  31. #                                      your plugin.
  32. # [+disable_code_mixing+] A boolean flag indicating whether all plugin
  33. #                         copies of a particular controller/helper should 
  34. #                         be loaded and allowed to override each other, 
  35. #                         or if the first matching file should be loaded 
  36. #                         instead. Defaults to false.
  37. #
  38. module Engines
  39.   # The set of all loaded plugins
  40.   mattr_accessor :plugins
  41.   self.plugins = Engines::Plugin::List.new  
  42.   
  43.   # List of extensions to load, can be changed in init.rb before calling Engines.init
  44.   mattr_accessor :rails_extensions
  45.   self.rails_extensions = %w(action_mailer asset_helpers routing migrations dependencies)
  46.   
  47.   # The name of the public directory to mirror public engine assets into.
  48.   # Defaults to <tt>RAILS_ROOT/public/plugin_assets</tt>.
  49.   mattr_accessor :public_directory
  50.   self.public_directory = File.join(RAILS_ROOT, 'public''plugin_assets')
  51.   # The table in which to store plugin schema information. Defaults to
  52.   # "plugin_schema_info".
  53.   mattr_accessor :schema_info_table
  54.   self.schema_info_table = "plugin_schema_info"
  55.   #--
  56.   # These attributes control the behaviour of the engines extensions
  57.   #++
  58.   
  59.   # Set this to true if views should *only* be loaded from plugins
  60.   mattr_accessor :disable_application_view_loading
  61.   self.disable_application_view_loading = false
  62.   
  63.   # Set this to true if controller/helper code shouldn't be loaded 
  64.   # from the application
  65.   mattr_accessor :disable_application_code_loading
  66.   self.disable_application_code_loading = false
  67.   
  68.   # Set this ti true if code should not be mixed (i.e. it will be loaded
  69.   # from the first valid path on $LOAD_PATH)
  70.   mattr_accessor :disable_code_mixing
  71.   self.disable_code_mixing = false
  72.   
  73.   # This is used to determine which files are candidates for the "code
  74.   # mixing" feature that the engines plugin provides, where classes from
  75.   # plugins can be loaded, and then code from the application loaded
  76.   # on top of that code to override certain methods.
  77.   mattr_accessor :code_mixing_file_types
  78.   self.code_mixing_file_types = %w(controller helper)
  79.   
  80.   class << self
  81.     def init
  82.       load_extensions
  83.       Engines::Assets.initialize_base_public_directory
  84.     end
  85.     
  86.     def logger
  87.       RAILS_DEFAULT_LOGGER
  88.     end
  89.     
  90.     def load_extensions
  91.       rails_extensions.each { |name| require "engines/rails_extensions/#{name}" }
  92.       # load the testing extensions, if we are in the test environment.
  93.       require "engines/testing" if RAILS_ENV == "test"
  94.     end
  95.     
  96.     def select_existing_paths(paths)
  97.       paths.select { |path| File.directory?(path) }
  98.     end  
  99.   
  100.     # The engines plugin will, by default, mix code from controllers and helpers,
  101.     # allowing application code to override specific methods in the corresponding
  102.     # controller or helper classes and modules. However, if other file types should
  103.     # also be mixed like this, they can be added by calling this method. For example,
  104.     # if you want to include "things" within your plugin and override them from
  105.     # your applications, you should use the following layout:
  106.     #
  107.     #   app/
  108.     #    +-- things/
  109.     #    |       +-- one_thing.rb
  110.     #    |       +-- another_thing.rb
  111.     #   ...
  112.     #   vendor/
  113.     #       +-- plugins/
  114.     #                +-- my_plugin/
  115.     #                           +-- app/
  116.     #                                +-- things/
  117.     #                                        +-- one_thing.rb
  118.     #                                        +-- another_thing.rb
  119.     #
  120.     # The important point here is that your "things" are named <whatever>_thing.rb,
  121.     # and that they are placed within plugin/app/things (the pluralized form of 'thing').
  122.     
  123.     # It's important to note that you'll also want to ensure that the "things" are
  124.     # on your load path in your plugin's init.rb:
  125.     #
  126.     #   Rails.plugins[:my_plugin].code_paths << "app/things"
  127.     #
  128.     def mix_code_from(*types)
  129.       self.code_mixing_file_types += types.map { |x| x.to_s.singularize }
  130.     end
  131.     
  132.     # A general purpose method to mirror a directory (+source+) into a destination
  133.     # directory, including all files and subdirectories. Files will not be mirrored
  134.     # if they are identical already (checked via FileUtils#identical?).
  135.     def mirror_files_from(source, destination)
  136.       return unless File.directory?(source)
  137.       
  138.       # TODO: use Rake::FileList#pathmap?    
  139.       source_files = Dir[source + "/**/*"]
  140.       source_dirs = source_files.select { |d| File.directory?(d) }
  141.       source_files -= source_dirs
  142.       
  143.       unless source_files.empty?
  144.         base_target_dir = File.join(destination, File.dirname(source_files.first))
  145.         #FileUtils.mkdir_p(base_target_dir)
  146.         FileUtils.mkdir_p(destination)
  147.       end
  148.       
  149.       source_dirs.each do |dir|
  150.         # strip down these paths so we have simple, relative paths we can
  151.         # add to the destination
  152.         target_dir = File.join(destination, dir.gsub(source, ''))
  153.         begin        
  154.           FileUtils.mkdir_p(target_dir)
  155.         rescue Exception => e
  156.           raise "Could not create directory #{target_dir}: /n" + e
  157.         end
  158.       end
  159.       
  160.       source_files.each do |file|
  161.         begin
  162.           target = File.join(destination, file.gsub(source, ''))
  163.           unless File.exist?(target) && FileUtils.identical?(file, target)
  164.             FileUtils.cp(file, target)
  165.           end 
  166.         rescue Exception => e
  167.           raise "Could not copy #{file} to #{target}: /n" + e 
  168.         end
  169.       end  
  170.     end   
  171.   end  
  172. end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值