ruby 创建块文件(样式表,厨房页面,布局)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 创建块文件(样式表,厨房页面,布局)相关的知识,希望对你有一定的参考价值。
desc 'Create block stylesheet file and kitchen page'
task :create_block, [:name] do |t, args|
block_name = args[:name]
if block_name == nil
print "Block name is required \n"
else
# TODO Check name for convention validity ('my-super-block', not 'mySuper_block')
# Create stylesheet file
style_file_path = "#{Rails.root}/app/assets/stylesheets/blocks/_#{block_name}.scss"
unless File.exists?(style_file_path)
File.open(style_file_path, 'w+') do |f|
f.write(".#{block_name} {}")
print "File #{style_file_path} created. \n"
end
else
print "File #{style_file_path} already exist. \n"
end
# Create kitchen page
kitchen_file_name = block_name.gsub('-', '_')
kitchen_file_path = "#{Rails.root}/app/views/kitchen/#{kitchen_file_name}.slim"
unless File.exists?(kitchen_file_path)
File.open(kitchen_file_path, 'w+') do |f|
f.write("h1 #{block_name}")
print "File #{kitchen_file_path} created. \n"
end
else
print "File #{kitchen_file_path} already exist. \n"
end
# Create template file
template_file_name = kitchen_file_name
template_file_dir = "#{Rails.root}/app/views/layouts/blocks/#{template_file_name}"
template_file_path = "#{Rails.root}/app/views/layouts/blocks/#{template_file_name}/_default.slim"
unless File.exists?(template_file_dir)
Dir.mkdir(template_file_dir)
File.open(template_file_path, 'w+') do |f|
f.write(".#{block_name} #{block_name}")
print "File #{template_file_path} created. \n"
end
else
print "File #{template_file_path} already exist. \n"
end
end
end
以上是关于ruby 创建块文件(样式表,厨房页面,布局)的主要内容,如果未能解决你的问题,请参考以下文章
如何在VSTS Wiki中使用样式或样式表?
如何利用EasyUI框架控制页面布局
微搭低代码样式开发-布局介绍
CSS样式表代码布局基础教程
Magento 2 - 如何在另一个 phtml 文件、xml 布局、静态块和 cms 页面中调用自定义 phtml 文件?
Ruby on Rails - 一个布局页面不同的内容