Class: Scaffold
Instance Attribute Summary
Attributes inherited from Path
Instance Method Summary collapse
- #create(name) ⇒ Object
-
#initialize(settings, default, args) ⇒ Scaffold
constructor
A new instance of Scaffold.
- #set_name(output_path, name) ⇒ Object
Methods inherited from Path
#aboslute_paths, #absolute_path, #initalize, #prepare_output_path, #prioritize
Constructor Details
#initialize(settings, default, args) ⇒ Scaffold
Returns a new instance of Scaffold.
5 6 7 8 9 10 |
# File 'lib/mako/scaffold.rb', line 5 def initialize settings, default, args @settings = settings @default = default @args = args end |
Instance Method Details
#create(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mako/scaffold.rb', line 12 def create name path = nil type = prioritize(:type, @args, @default) devkit_path = prioritize(:dev_kit, @args, @settings, @default) output_path = prepare_output_path @args, @default # Check for the DevKit if devkit_path.empty? puts "Mako can't find your Materia Dev Kit".red puts "Please set MAKO_DEV_KIT environment variable or the --dev-kit option".red abort end if path.nil? output_path = output_path+"/"+name.gsub(" ", "-").downcase else output_path = output_path+"/"+path+"/"+name.gsub(" ", "-").downcase end if File.exist?(output_path) puts "Error:"+"#{output_path} already exists! Aborting!".red abort end # Check to see if the selected scaffold can be found source_dir = devkit_path+'templates/'+type puts source_dir if File::exists? source_dir # copy the template into the scaffolded widget FileUtils.cp_r source_dir, output_path FileUtils.chmod 0777, output_path set_name output_path, name end output = "Created scaffold of type "+type puts output.green end |
#set_name(output_path, name) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/mako/scaffold.rb', line 62 def set_name output_path, name # Now replace __DefaultWidget__ with the desired name in all files Dir[output_path+'/**/*.{css,scss,sass,js,coffee,html,htm,php,yaml,md}'].each do |file| text = File.read(file) updated = text.gsub(/__DefaultWidget__/, name) updated = updated.gsub(/__DefaultWidgetCondensed__/, name.gsub(/\s+/, '')) File.open(file, 'w') { |fpath| fpath.puts(updated)} end end |