新手问题 网页模板中的若干插件包含 JS、CSS 和图片资源如何不拆分集成到 Rails 中?

kouunn · 2016年10月07日 · 最后由 Katrina123 回复于 2017年04月26日 · 2339 次阅读

如题,下面是目录结构,有什么好方法吗?

|____.DS_Store
|____apple-style
| |____.DS_Store
| |____css
| | |____apple-style.css
| |____images
| | |____bt-next.png
| | |____bt-pause.png
| | |____bt-play.png
| | |____bt-prev.png
| | |____ipad-shadow.png
| | |____ipad.png
| | |____iphone-shadow.png
| | |____iphone.png
| | |____status-bar.png
| |____js
| | |____apple-style.js
| | |____sequence.jquery-min.js
|____back-to-top.js
|____backstretch
| |____jquery.backstretch.min.js
|____bootstrap
| |____.DS_Store
| |____css
| | |____bootstrap-responsive.min.css
| | |____bootstrap.min.css
| |____img
| | |____glyphicons-halflings-white.png
| | |____glyphicons-halflings.png
| |____js
| | |____bootstrap.min.js
|____bxslider
| |____images
| | |____bx_loader.gif
| | |____controls.png
| |____jquery.bxslider.css
| |____jquery.bxslider.js
|____countdown
| |____css
| | |____countdown.css
| |____jquery.countdown.js
|____fancybox
| |____source
| | |____blank.gif
| | |____fancybox_loading.gif
| | |____fancybox_overlay.png
| | |____fancybox_sprite.png
| | |____jquery.fancybox.css
| | |____jquery.fancybox.pack.js
|____flexslider
| |____.DS_Store
| |____flexslider.css
| |____images
| | |____bg_direction_nav.png
| |____jquery.flexslider-min.js
|____font-awesome
| |____.DS_Store
| |____css
| | |____font-awesome.css
| |____font
| | |____fontawesome-webfont.eot
| | |____fontawesome-webfont.ttf
| | |____fontawesome-webfont.woff
| | |____fontawesome-webfont_2d2816fe.eot
|____glyphicons
| |____css
| | |____glyphicons.css
| |____fonts
| | |____glyphicons-regular.eot
| | |____glyphicons-regular.svg
| | |____glyphicons-regular.ttf
| | |____glyphicons-regular.woff
| | |____glyphicons-regular_2d2816fe.eot
| |____images
| | |____glyphicons-white.png
| | |____glyphicons-white.svg
| | |____glyphicons.png
|____gmap
| |____gmap.js
|____horizontal-parallax
| |____css
| | |____horizontal-parallax.css
| |____images
| | |____aeroplane.png
| | |____balloon.png
| | |____bg-sky.png
| | |____bg-text.png
| | |____bt-next1.png
| | |____bt-prev1.png
| | |____kite.png
| |____js
| | |____horizontal-parallax.js
| | |____sequence.jquery-min.js
|____parallax-slider
| |____.DS_Store
| |____css
| | |____parallax-slider.css
| |____img
| | |____1.png
| | |____arrows.png
| | |____bg-heading.png
| | |____bg-text.png
| | |____bg.jpg
| | |____html5andcss3.png
| |____js
| | |____jquery.cslider.js
| | |____modernizr.js
|____portfolioSorting
| |____css
| | |____sorting.css
| |____img
| | |____10.jpg
| | |____2.jpg
| | |____3.jpg
| | |____4.jpg
| | |____5.jpg
| | |____6.jpg
| | |____7.jpg
| | |____8.jpg
| | |____9.jpg
| |____js
| | |____jquery.quicksand.js
| | |____sorting.js
|____revolution_slider
| |____css
| | |____rs-style.css
| |____rs-plugin
| | |____assets
| | | |____arrow_left.png
| | | |____arrow_left2.png
| | | |____arrow_right.png
| | | |____arrow_right2.png
| | | |____arrowleft.png
| | | |____arrowright.png
| | | |____boxed_bgtile.png
| | | |____bullet.png
| | | |____bullet_boxed.png
| | | |____bullets.png
| | | |____bullets2.png
| | | |____coloredbg.png
| | | |____large_left.png
| | | |____large_right.png
| | | |____loader.gif
| | | |____navigdots.png
| | | |____navigdots_bgtile.png
| | | |____shadow1.png
| | | |____shadow2.png
| | | |____shadow3.png
| | | |____small_left.png
| | | |____small_left_boxed.png
| | | |____small_right.png
| | | |____small_right_boxed.png
| | | |____timer.png
| | |____css
| | | |____settings.css
| | |____images
| | | |____gradient
| | | | |____g30.png
| | | | |____g40.png
| | |____js
| | | |____jquery.themepunch.plugins.min.js
| | | |____jquery.themepunch.revolution.min.js

自己 host 啊。

可以放到public目录下

# many many config.assets.paths << ...
config.assets.paths << Rails.root.join(
        'vendor',
        'assets',
        'bower_components',
        'bootstrap-sass-official',
        'vendor',
        'assets',
        'fonts'
    )
config.assets.precompile += %w(.svg .eot .woff .ttf)

like this.

看得出大多都是 js 库,缕一下,直接用 bower 管理也行。

直接扔到 public 目录下

#3 楼 @flowerwrong 能再说的具体点吗,http://zjyd.sc.chinaz.com/Files/DownLoad/moban/201403/chahua3215.rar 如何把这个集成到一个新的的 rails 项目里面,谢谢啊

#5 楼 @kouunn 参考 rails bower 的做法,如果觉得麻烦,可以按照二楼五楼的,直接丢 public,这样简单

我是新手,想请教一下你是怎么解决的

#8 楼 @Katrina123 放到 public 目录下,然后就可以用了。实在不行,你把模版贴出来我帮你试试看!

我已经解决了,用 Asset Pipeline.把下载的模板里的 css 放到 app/assets/stylesheets 里,js 放到 app/assets/javascripts 里,图片放到 app/assets/images 里,其中有嵌套文件夹的还是按照它指定的路径。请注意图片的具体路径中没有 app/.比如<img src="assets/a/1.jpg"/>而不是<img src="app/assets/a/1.jpg"/>

需要 登录 后方可回复, 如果你还没有账号请 注册新账号