forked from anykeyh/clear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yacine Petitprez
committed
Mar 21, 2018
1 parent
d9161d4
commit 3fb53ba
Showing
6 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
require "ecr" | ||
|
||
module Clear::CLI | ||
record Generator, name : String, desc : String, callback : Hash(Symbol, String) -> Void | ||
module Generate | ||
record Generator, name : String, desc : String, callback : Hash(Symbol, String) -> Void | ||
|
||
@@generators : Hash(String, Generator) = {} of String => Generator | ||
@@generators : Hash(String, Generator) = {} of String => Generator | ||
|
||
def self.add_generator(name, desc, &block : Hash(Symbol, String) -> Void) | ||
add_generator Generator.new(name, desc, block) | ||
end | ||
def self.add_generator(name, desc, &block : Hash(Symbol, String) -> Void) | ||
add_generator Generator.new(name, desc, block) | ||
end | ||
|
||
def self.add_generator(generator : Generator) | ||
@@generators[generator.name] = generator | ||
end | ||
def self.add_generator(generator : Generator) | ||
@@generators[generator.name] = generator | ||
end | ||
|
||
def self.run_generator(name, options, directory : String? = nil) | ||
opts = {} of Symbol => String | ||
def self.run_generator(name, options, directory : String? = nil) | ||
opts = {} of Symbol => String | ||
|
||
opts[:email] = `git config user.email`.chomp || "[email protected]" | ||
opts[:user_name] = `git config user.name`.chomp || "Your Name" | ||
opts[:app_name] = "MyApp" | ||
opts[:app_name_underscore] = opts[:app_name].underscore | ||
opts[:directory] = directory || opts[:app_name_underscore] | ||
opts[:email] = `git config user.email`.chomp || "[email protected]" | ||
opts[:user_name] = `git config user.name`.chomp || "Your Name" | ||
opts[:app_name] = "MyApp" | ||
opts[:app_name_underscore] = opts[:app_name].underscore | ||
opts[:directory] = directory || opts[:app_name_underscore] | ||
|
||
@@generators[name].callback.call(opts) | ||
end | ||
@@generators[name].callback.call(opts) | ||
end | ||
|
||
macro ecr_to_s(file, opts) | ||
io = IO::Memory.new | ||
ECR.embed {{file}}, io | ||
io.to_s | ||
end | ||
|
||
macro ecr_to_s(file, opts) | ||
io = IO::Memory.new | ||
ECR.embed {{file}}, io | ||
io.to_s | ||
def self.run(args) | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Clear::CLI::Generate.add_generator("migration", | ||
"Create a new migration") do |opts| | ||
g = Generate::Generator.new | ||
g.target_directory = "." | ||
|
||
timestamp = Time.now.epoch.to_s.rjust(10, '0') | ||
|
||
file_name = "#{timestamp}_#{opts[:name].underscore}.cr" | ||
opts[:class_name] = "#{opts[:name].camelcase}#{timestamp}" | ||
|
||
g.in_directory "src/db/migrations" do | ||
g.file(file_name, "./templates/migration.ecr") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module Clear::CLI::TableToModel | ||
def self.run(opts) | ||
pp opts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class <%= opts[:class_name] %> | ||
include Clear::Migration | ||
|
||
def change(dir) | ||
# TODO: Fill migration | ||
end | ||
end |