扩展File类
module Utils
class File
class << self
# 递归调用返回目录中的所有文件
def findfiles(dir, &block)
files = []
if ::File.exist?(dir)
if ::File.ftype(dir) == 'file'
files << dir
block.call(dir) if block
else
Dir.foreach(dir) do |entry|
unless [".", "..", "_svn", ".svn"].include?(entry)
files += findfiles("#{dir}/#{entry}", &block)
end
end
end
else
p "No such file or directory - #{dir}"
end
files
end
# 所有目录
def directories(dir, options={}, &block)
skip_dir = (options[:skip_dir]||[]) + [".", "..", "_svn", ".svn"]
Dir.entries(dir).collect do |item|
if ::File.ftype(::File.join(dir, item)) == 'directory' && !skip_dir.include?(item)
block.call(item) if block
item
end
end.compact
end
end
end
end
rake命令
require 'tempfile'
require 'yaml'
# 添加命名空间
namespace :dev do
#添加描述
# 在最终发布前,需要运行该命令,对javascript、css进行合并和压缩处理。
desc 'Compress javascript and stylesheets'
task :compress do
compress_of(:type=>'js')
compress_of(:type=>'css')
end
private
def compress_of(options)
build_path = "#{RAILS_ROOT}/lib/tasks/compressor"
command = "java -jar #{build_path}/yuicompressor-2.4.2.jar --charset utf8"
type = options[:type] || 'js'
work_path = "#{RAILS_ROOT}/public/#{type == 'js' ? 'javascripts' : 'stylesheets'}"
temp = Tempfile.new('compress')
files = get_files_from_config(type == 'js' ? 'javascripts' : 'stylesheets', 'development')
File.open(temp.path, 'a') do |f|
files.each do |file|
f.puts File.open(file, 'r') { |js| js.read }
puts "merge #{file}"
end
end
output_file = "#{work_path}/#{options[:output] || "all.#{type}"}"
system("#{command} --type #{type} -o #{output_file} #{temp.path}")
puts "build one compress file to #{output_file}"
puts ''
end
# 从config.yml配置文件中读取文件列表
def get_files_from_config(type, name = RAILS_ENV)
configuration_file = "#{RAILS_ROOT}/public/#{type}/config.yml"
config = YAML::load(ERB.new(IO.read(configuration_file)).result)
env_config = config[name]||{}
exclude_config = config['exclude']||{} #有些文件可能需要排除
work_path = "#{RAILS_ROOT}/public"
files = []
(env_config['items']-(exclude_config['items']||[])).each do |item|
tmp_files = []
Utils::File.findfiles("#{work_path}/#{type}/#{item}") do |file|
tmp_files << file #.sub(work_path, '')
end
files += tmp_files.sort
end
files
end
end
config.yml 格式
development: &development
items:
- jquery-ui-1.7.2.custom.css #jquery默认的uicss
- jquery-ui-1.7.2.pack.css #修改jquery默认的uicss
# 注意,为了加快产品执行效率,其实在产品模式下并不会用该配置,在此仅作为示例
# 直接在页面中硬编码为safore.js
# 请参见: D:\App\www\eb\trunk\app\views\layouts\a\_meta.rhtml
production:
items:
- all.css
分享到:
相关推荐
使用halcon进行测量,使用的是rake算子;使用halcon进行测量,使用的是rake算子;
rake详解
本实验报告通过对RAKE接收机的概念、原理和性能的描述和分析,通过Matlab仿真,模拟RAKE接收机的误码性能,有力的说明了RAKE接收机可以有效地利用多径分量,把多径能量收集起来,变矢量和为代数和,从而有效减小多...
rake接收机仿真程序,包括多个仿真
halcon提供给我们使用的测量矩形只能返回一个点,操作...rake工具封装了三个函数来完成,代码不少,下面我就来展示详细的代码和实际效果。 原文链接:https://blog.csdn.net/weixin_38566632/article/details/117744728
多径信号下RAKE接收和均衡的作用分析
针对异地通信网络的3G最佳接收机matlab程序。设计的三种RAKE接收机程序。非常实用。
使用简单的 rake 命令整理您的桌面、下载和其他杂乱文件夹。 简单有效。 用法 在开始使用 Mess Organizer 之前,您需要在您的操作系统上安装和 。 如果你已经安装了 Rake gem,只需将这个 repo 克隆到你想要组织的...
rake for rails rake-0.8.7安装rails必须资源
RAKE接收机的延时估计和合并方式,高芳,张晓光,RAKE接收机能够实现多径接收,有效对抗多径干扰,其关键技术包括时延估计和合并方式。论文首先对匹配滤波和逆滤波器两种时延估计��
rake-0.8.3.gem redmind安装必需
来自practical rails social networking sites上的第二章的实例,应用了数据导入,导入数据到mysql后就可以使用,命令: rake db:migrate(进入文件夹"railscoder")
rake for rails 安装rails资源
Rake接收机性能仿真(与非Rake接收机对比).pdfRake接收机性能仿真(与非Rake接收机对比).pdf
ofdm的一个实例,很简单但个人觉得蛮不错的,故推荐下
rake接收(多径分集技术)+matlab仿真程序
rake-0.8.7 for rails 安装rails必须的资源
采用simulink仿真除直接序列扩频系统 的rake接收仿真,个人感觉很不错,和大家分享一下,
为了提高传统Rake接收机在无线通信系统中的性能,消除信号间的干扰和噪声,采用一种改进的基于最小均方误差(LMS)算法的Rake接收机,该结构针对传统的MRCRake接收机需通过增加分支数来提高性能,而MMSERake接收...
基于Matlab的Rake接受机的仿真 发射端包括分集发射,接收端的最大比值合并、等增益合并以及选择式合并方式