Skip to content

Instantly share code, notes, and snippets.

@panych
Created April 29, 2014 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panych/11393576 to your computer and use it in GitHub Desktop.
Save panych/11393576 to your computer and use it in GitHub Desktop.
Create block files (stylesheet, kitchen page, layout)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment