-
Notifications
You must be signed in to change notification settings - Fork 0
/
padrino_template.rb
95 lines (75 loc) · 3.82 KB
/
padrino_template.rb
1
2
3
4
5
6
7
8
9
10
11
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# # my_template.rb
project :test => :rspec,
:orm => :activerecord,
:renderer => :haml,
:stylesheet => :scss,
:migration_format => :timestamp
# # generate :model, "post title:string body:text"
# # generate :model, "user name:string address:string post_code:string"
# # generate :controller, "posts get:index get:new post:new"
# # generate :migration, "AddEmailToUser email:string"
# # require_dependencies 'nokogiri'
generate :app, 'mobile'
generate :app, 'api'
empty_directory "public/fonts"
empty_directory "build"
require 'fileutils'
# setup required paths
rubonic_root_path = Gem::Specification.find_by_name('rubonic').gem_dir
rubonic_templates_path = "#{rubonic_root_path}/padrino_templates"
public_js_directory = File.join(destination_root, 'public/javascripts')
public_css_directory = File.join(destination_root, 'public/stylesheets')
bower_framework7_path = File.join(destination_root, 'bower_components/Framework7/dist')
# Copy our templates into the directories in the padrino project
add_file 'config/assets.yml', File.read("#{rubonic_templates_path}/assets.yml")
add_file 'mobile/views/index.erb', File.read("#{rubonic_templates_path}/index.erb")
add_file 'config/rubonic.yml', File.read("#{rubonic_templates_path}/rubonic.yml")
add_file 'app/stylesheets/inuit.scss', File.read("#{rubonic_templates_path}/inuit.scss")
add_file 'package.json', File.read("#{rubonic_templates_path}/package.json")
add_file 'bower.json', File.read("#{rubonic_templates_path}/bower.json")
add_file "#{public_js_directory}/framework7_loader.js", File.read("#{rubonic_templates_path}/framework7_loader.js")
# add additional requirements into the necessary files
inject_into_file "Gemfile", "gem 'rubonic'", :after => "source 'https://rubygems.org'\n"
inject_into_file "Rakefile", "require 'rubonic'", :after => "require 'padrino-core/cli/rake'\n"
inject_into_file "Rakefile", "require 'rubonic/tasks'\n", :after => "require 'rubonic'\n"
inject_into_file "mobile/app.rb", File.read("#{rubonic_templates_path}/app.rb"),
:after => "enable :sessions\n"
prepend_file "mobile/app.rb", "require 'padrino-helpers'\n"
# Run npm and bower to get the required libraries
system "cd #{destination_root} && npm install"
system "cd #{destination_root} && ./node_modules/bower/bin/bower install --save"
# Copy required libraries to correct directories
FileUtils.cp "#{destination_root}/bower_components/angular/angular.js", "#{public_js_directory}"
FileUtils.cp "#{destination_root}/bower_components/angular-ui-router/release/angular-ui-router.js", "#{public_js_directory}"
FileUtils.cp "#{bower_framework7_path}/js/framework7.js", "#{public_js_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.ios.css", "#{public_css_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.ios.colors.css", "#{public_css_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.ios.rtl.css", "#{public_css_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.material.css", "#{public_css_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.material.colors.css", "#{public_css_directory}"
FileUtils.cp "#{bower_framework7_path}/css/framework7.material.rtl.css", "#{public_css_directory}"
git :init
# Ignore npm/bower specific stuff
ignore = <<-IGNORE
node_modules/
bower_components/
IGNORE
append_file '.gitignore', ignore
# run 'bundle'
# bundle
# rake ""
# git :init
# # inject_into_file "models/post.rb","#Hello", :after => "end\n"
# # inject_into_file "models/user.rb", :after => "end\n" do <<-'RUBY'
# # def HelloWorld(message)
# # "Message: #{message}"
# # end
# # RUBY
# # end
# # rake "ar:create ar:migrate"
# # initializer :test, "# Example"
# # app :testapp do
# # generate :controller, "users get:index"
# # end
# # git :add, "."
# # git :commit, "-m 'second commit'"