CommunityEngine 是Rails下一个相当不错的社会化网络插件。
在linux下测试使用时候,相当的顺利,但在Windows下使用时,且在启动的时候出现以下错误,虽然可以正常启动,却发现样式全没了。
- Attemptingtocopypluginassetsfrom'E:/workspace/beeblio/vendor/plugins/community_engine/assets'to'E:/workspace/beeblio/public/plugin_assets'
- WARNING:Couldn'tcreatethepublicfilestructureforplugin'community_engine';Errorfollows:
- Invalidargument-E:/workspace/beeblio/public/plugin_assets/community_engine/E:
- Attemptingtocopypluginassetsfrom'E:/workspace/beeblio/vendor/plugins/community_engine/engine_plugins/tiny_mce/public'to'E:/workspace/beeblio/public/plugin_assets'
- WARNING:Couldn'tcreatethepublicfilestructureforplugin'tiny_mce';Errorfollows:
- Invalidargument-E:/workspace/beeblio/public/plugin_assets/tiny_mce/E:
- checkingplugin'engines'for'application_helper'
- 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。
- require'active_support'
- requireFile.join(File.dirname(__FILE__),'engines/plugin')
- requireFile.join(File.dirname(__FILE__),'engines/plugin/list')
- requireFile.join(File.dirname(__FILE__),'engines/plugin/loader')
- requireFile.join(File.dirname(__FILE__),'engines/plugin/locator')
- requireFile.join(File.dirname(__FILE__),'engines/assets')
- requireFile.join(File.dirname(__FILE__),'engines/rails_extensions/rails')
- #==Parameters
- #
- #TheEnginesmodulehasanumberofpublicconfigurationparameters:
- #
- #[+public_directory+]Thedirectoryintowhichpluginassetsshouldbe
- #mirrored.Defaultsto<tt>RAILS_ROOT/public/plugin_assets</tt>.
- #[+schema_info_table+]Thetabletousewhenstoringpluginmigration
- #versioninformation.Defaultsto+plugin_schema_info+.
- #
- #Additionally,thereareafewflagswhichcontrolthebehaviourof
- #someofthefeaturestheenginespluginaddstoRails:
- #
- #[+disable_application_view_loading+]Abooleanflagdeterminingwhether
- #ornotviewsshouldbeloadedfrom
- #themain<tt>app/views</tt>directory.
- #Defaultstofalse;probablyonly
- #usefulwhentestingyourplugin.
- #[+disable_application_code_loading+]Abooleanflagdeterminingwhether
- #ornottoloadcontrollers/helpers
- #fromthemain+app+directory,
- #ifcorrespondingcodeexistswithin
- #aplugin.Defaultstofalse;again,
- #probablyonlyusefulwhentesting
- #yourplugin.
- #[+disable_code_mixing+]Abooleanflagindicatingwhetherallplugin
- #copiesofaparticularcontroller/helpershould
- #beloadedandallowedtooverrideeachother,
- #orifthefirstmatchingfileshouldbeloaded
- #instead.Defaultstofalse.
- #
- moduleEngines
- #Thesetofallloadedplugins
- mattr_accessor:plugins
- self.plugins=Engines::Plugin::List.new
- #Listofextensionstoload,canbechangedininit.rbbeforecallingEngines.init
- mattr_accessor:rails_extensions
- self.rails_extensions=%w(action_mailerasset_helpersroutingmigrationsdependencies)
- #Thenameofthepublicdirectorytomirrorpublicengineassetsinto.
- #Defaultsto<tt>RAILS_ROOT/public/plugin_assets</tt>.
- mattr_accessor:public_directory
- self.public_directory=File.join(RAILS_ROOT,'public','plugin_assets')
- #Thetableinwhichtostorepluginschemainformation.Defaultsto
- #"plugin_schema_info".
- mattr_accessor:schema_info_table
- self.schema_info_table="plugin_schema_info"
- #--
- #Theseattributescontrolthebehaviouroftheenginesextensions
- #++
- #Setthistotrueifviewsshould*only*beloadedfromplugins
- mattr_accessor:disable_application_view_loading
- self.disable_application_view_loading=false
- #Setthistotrueifcontroller/helpercodeshouldn'tbeloaded
- #fromtheapplication
- mattr_accessor:disable_application_code_loading
- self.disable_application_code_loading=false
- #Setthistitrueifcodeshouldnotbemixed(i.e.itwillbeloaded
- #fromthefirstvalidpathon$LOAD_PATH)
- mattr_accessor:disable_code_mixing
- self.disable_code_mixing=false
- #Thisisusedtodeterminewhichfilesarecandidatesforthe"code
- #mixing"featurethattheenginespluginprovides,whereclassesfrom
- #pluginscanbeloaded,andthencodefromtheapplicationloaded
- #ontopofthatcodetooverridecertainmethods.
- mattr_accessor:code_mixing_file_types
- self.code_mixing_file_types=%w(controllerhelper)
- class<<self
- definit
- load_extensions
- Engines::Assets.initialize_base_public_directory
- end
- deflogger
- RAILS_DEFAULT_LOGGER
- end
- defload_extensions
- rails_extensions.each{|name|require"engines/rails_extensions/#{name}"}
- #loadthetestingextensions,ifweareinthetestenvironment.
- require"engines/testing"ifRAILS_ENV=="test"
- end
- defselect_existing_paths(paths)
- paths.select{|path|File.directory?(path)}
- end
- #Theenginespluginwill,bydefault,mixcodefromcontrollersandhelpers,
- #allowingapplicationcodetooverridespecificmethodsinthecorresponding
- #controllerorhelperclassesandmodules.However,ifotherfiletypesshould
- #alsobemixedlikethis,theycanbeaddedbycallingthismethod.Forexample,
- #ifyouwanttoinclude"things"withinyourpluginandoverridethemfrom
- #yourapplications,youshouldusethefollowinglayout:
- #
- #app/
- #+--things/
- #|+--one_thing.rb
- #|+--another_thing.rb
- #...
- #vendor/
- #+--plugins/
- #+--my_plugin/
- #+--app/
- #+--things/
- #+--one_thing.rb
- #+--another_thing.rb
- #
- #Theimportantpointhereisthatyour"things"arenamed<whatever>_thing.rb,
- #andthattheyareplacedwithinplugin/app/things(thepluralizedformof'thing').
- #
- #It'simportanttonotethatyou'llalsowanttoensurethatthe"things"are
- #onyourloadpathinyourplugin'sinit.rb:
- #
- #Rails.plugins[:my_plugin].code_paths<<"app/things"
- #
- defmix_code_from(*types)
- self.code_mixing_file_types+=types.map{|x|x.to_s.singularize}
- end
- #Ageneralpurposemethodtomirroradirectory(+source+)intoadestination
- #directory,includingallfilesandsubdirectories.Fileswillnotbemirrored
- #iftheyareidenticalalready(checkedviaFileUtils#identical?).
- defmirror_files_from(source,destination)
- returnunlessFile.directory?(source)
- #TODO:useRake::FileList#pathmap?
- source_files=Dir[source+"/**/*"]
- source_dirs=source_files.select{|d|File.directory?(d)}
- source_files-=source_dirs
- unlesssource_files.empty?
- base_target_dir=File.join(destination,File.dirname(source_files.first))
- #FileUtils.mkdir_p(base_target_dir)
- FileUtils.mkdir_p(destination)
- end
- source_dirs.eachdo|dir|
- #stripdownthesepathssowehavesimple,relativepathswecan
- #addtothedestination
- target_dir=File.join(destination,dir.gsub(source,''))
- begin
- FileUtils.mkdir_p(target_dir)
- rescueException=>e
- raise"Couldnotcreatedirectory#{target_dir}:\n"+e
- end
- end
- source_files.eachdo|file|
- begin
- target=File.join(destination,file.gsub(source,''))
- unlessFile.exist?(target)&&FileUtils.identical?(file,target)
- FileUtils.cp(file,target)
- end
- rescueException=>e
- raise"Couldnotcopy#{file}to#{target}:\n"+e
- end
- end
- end
- end
- end
本文解决了在Windows环境下使用Rails插件CommunityEngine时遇到的样式丢失问题。通过修改Engines插件中的代码,确保了公共资产文件能够正确复制,从而恢复了社区引擎的样式。
2762

被折叠的 条评论
为什么被折叠?



