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

本文解决了在Windows环境下使用Rails插件CommunityEngine时遇到的样式丢失问题。通过修改Engines插件中的代码,确保了公共资产文件能够正确复制,从而恢复了社区引擎的样式。

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

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

  1. Attemptingtocopypluginassetsfrom'E:/workspace/beeblio/vendor/plugins/community_engine/assets'to'E:/workspace/beeblio/public/plugin_assets'
  2. WARNING:Couldn'tcreatethepublicfilestructureforplugin'community_engine';Errorfollows:
  3. Invalidargument-E:/workspace/beeblio/public/plugin_assets/community_engine/E:
  4. Attemptingtocopypluginassetsfrom'E:/workspace/beeblio/vendor/plugins/community_engine/engine_plugins/tiny_mce/public'to'E:/workspace/beeblio/public/plugin_assets'
  5. WARNING:Couldn'tcreatethepublicfilestructureforplugin'tiny_mce';Errorfollows:
  6. Invalidargument-E:/workspace/beeblio/public/plugin_assets/tiny_mce/E:
  7. checkingplugin'engines'for'application_helper'
  8. checkingplugin'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. requireFile.join(File.dirname(__FILE__),'engines/plugin')
  3. requireFile.join(File.dirname(__FILE__),'engines/plugin/list')
  4. requireFile.join(File.dirname(__FILE__),'engines/plugin/loader')
  5. requireFile.join(File.dirname(__FILE__),'engines/plugin/locator')
  6. requireFile.join(File.dirname(__FILE__),'engines/assets')
  7. requireFile.join(File.dirname(__FILE__),'engines/rails_extensions/rails')
  8. #==Parameters
  9. #
  10. #TheEnginesmodulehasanumberofpublicconfigurationparameters:
  11. #
  12. #[+public_directory+]Thedirectoryintowhichpluginassetsshouldbe
  13. #mirrored.Defaultsto<tt>RAILS_ROOT/public/plugin_assets</tt>.
  14. #[+schema_info_table+]Thetabletousewhenstoringpluginmigration
  15. #versioninformation.Defaultsto+plugin_schema_info+.
  16. #
  17. #Additionally,thereareafewflagswhichcontrolthebehaviourof
  18. #someofthefeaturestheenginespluginaddstoRails:
  19. #
  20. #[+disable_application_view_loading+]Abooleanflagdeterminingwhether
  21. #ornotviewsshouldbeloadedfrom
  22. #themain<tt>app/views</tt>directory.
  23. #Defaultstofalse;probablyonly
  24. #usefulwhentestingyourplugin.
  25. #[+disable_application_code_loading+]Abooleanflagdeterminingwhether
  26. #ornottoloadcontrollers/helpers
  27. #fromthemain+app+directory,
  28. #ifcorrespondingcodeexistswithin
  29. #aplugin.Defaultstofalse;again,
  30. #probablyonlyusefulwhentesting
  31. #yourplugin.
  32. #[+disable_code_mixing+]Abooleanflagindicatingwhetherallplugin
  33. #copiesofaparticularcontroller/helpershould
  34. #beloadedandallowedtooverrideeachother,
  35. #orifthefirstmatchingfileshouldbeloaded
  36. #instead.Defaultstofalse.
  37. #
  38. moduleEngines
  39. #Thesetofallloadedplugins
  40. mattr_accessor:plugins
  41. self.plugins=Engines::Plugin::List.new
  42. #Listofextensionstoload,canbechangedininit.rbbeforecallingEngines.init
  43. mattr_accessor:rails_extensions
  44. self.rails_extensions=%w(action_mailerasset_helpersroutingmigrationsdependencies)
  45. #Thenameofthepublicdirectorytomirrorpublicengineassetsinto.
  46. #Defaultsto<tt>RAILS_ROOT/public/plugin_assets</tt>.
  47. mattr_accessor:public_directory
  48. self.public_directory=File.join(RAILS_ROOT,'public','plugin_assets')
  49. #Thetableinwhichtostorepluginschemainformation.Defaultsto
  50. #"plugin_schema_info".
  51. mattr_accessor:schema_info_table
  52. self.schema_info_table="plugin_schema_info"
  53. #--
  54. #Theseattributescontrolthebehaviouroftheenginesextensions
  55. #++
  56. #Setthistotrueifviewsshould*only*beloadedfromplugins
  57. mattr_accessor:disable_application_view_loading
  58. self.disable_application_view_loading=false
  59. #Setthistotrueifcontroller/helpercodeshouldn'tbeloaded
  60. #fromtheapplication
  61. mattr_accessor:disable_application_code_loading
  62. self.disable_application_code_loading=false
  63. #Setthistitrueifcodeshouldnotbemixed(i.e.itwillbeloaded
  64. #fromthefirstvalidpathon$LOAD_PATH)
  65. mattr_accessor:disable_code_mixing
  66. self.disable_code_mixing=false
  67. #Thisisusedtodeterminewhichfilesarecandidatesforthe"code
  68. #mixing"featurethattheenginespluginprovides,whereclassesfrom
  69. #pluginscanbeloaded,andthencodefromtheapplicationloaded
  70. #ontopofthatcodetooverridecertainmethods.
  71. mattr_accessor:code_mixing_file_types
  72. self.code_mixing_file_types=%w(controllerhelper)
  73. class<<self
  74. definit
  75. load_extensions
  76. Engines::Assets.initialize_base_public_directory
  77. end
  78. deflogger
  79. RAILS_DEFAULT_LOGGER
  80. end
  81. defload_extensions
  82. rails_extensions.each{|name|require"engines/rails_extensions/#{name}"}
  83. #loadthetestingextensions,ifweareinthetestenvironment.
  84. require"engines/testing"ifRAILS_ENV=="test"
  85. end
  86. defselect_existing_paths(paths)
  87. paths.select{|path|File.directory?(path)}
  88. end
  89. #Theenginespluginwill,bydefault,mixcodefromcontrollersandhelpers,
  90. #allowingapplicationcodetooverridespecificmethodsinthecorresponding
  91. #controllerorhelperclassesandmodules.However,ifotherfiletypesshould
  92. #alsobemixedlikethis,theycanbeaddedbycallingthismethod.Forexample,
  93. #ifyouwanttoinclude"things"withinyourpluginandoverridethemfrom
  94. #yourapplications,youshouldusethefollowinglayout:
  95. #
  96. #app/
  97. #+--things/
  98. #|+--one_thing.rb
  99. #|+--another_thing.rb
  100. #...
  101. #vendor/
  102. #+--plugins/
  103. #+--my_plugin/
  104. #+--app/
  105. #+--things/
  106. #+--one_thing.rb
  107. #+--another_thing.rb
  108. #
  109. #Theimportantpointhereisthatyour"things"arenamed<whatever>_thing.rb,
  110. #andthattheyareplacedwithinplugin/app/things(thepluralizedformof'thing').
  111. #
  112. #It'simportanttonotethatyou'llalsowanttoensurethatthe"things"are
  113. #onyourloadpathinyourplugin'sinit.rb:
  114. #
  115. #Rails.plugins[:my_plugin].code_paths<<"app/things"
  116. #
  117. defmix_code_from(*types)
  118. self.code_mixing_file_types+=types.map{|x|x.to_s.singularize}
  119. end
  120. #Ageneralpurposemethodtomirroradirectory(+source+)intoadestination
  121. #directory,includingallfilesandsubdirectories.Fileswillnotbemirrored
  122. #iftheyareidenticalalready(checkedviaFileUtils#identical?).
  123. defmirror_files_from(source,destination)
  124. returnunlessFile.directory?(source)
  125. #TODO:useRake::FileList#pathmap?
  126. source_files=Dir[source+"/**/*"]
  127. source_dirs=source_files.select{|d|File.directory?(d)}
  128. source_files-=source_dirs
  129. unlesssource_files.empty?
  130. base_target_dir=File.join(destination,File.dirname(source_files.first))
  131. #FileUtils.mkdir_p(base_target_dir)
  132. FileUtils.mkdir_p(destination)
  133. end
  134. source_dirs.eachdo|dir|
  135. #stripdownthesepathssowehavesimple,relativepathswecan
  136. #addtothedestination
  137. target_dir=File.join(destination,dir.gsub(source,''))
  138. begin
  139. FileUtils.mkdir_p(target_dir)
  140. rescueException=>e
  141. raise"Couldnotcreatedirectory#{target_dir}:\n"+e
  142. end
  143. end
  144. source_files.eachdo|file|
  145. begin
  146. target=File.join(destination,file.gsub(source,''))
  147. unlessFile.exist?(target)&&FileUtils.identical?(file,target)
  148. FileUtils.cp(file,target)
  149. end
  150. rescueException=>e
  151. raise"Couldnotcopy#{file}to#{target}:\n"+e
  152. end
  153. end
  154. end
  155. end
  156. end
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值