appgen 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/appgen.gemspec +1 -0
- data/examples/blogdemo.txt +1 -1
- data/lib/appgen/cli.rb +1 -1
- data/lib/appgen/generator.rb +75 -2
- data/lib/appgen/loader.rb +4 -6
- data/lib/appgen/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0df51490f348d4940655c3e787dd2701644bac
|
4
|
+
data.tar.gz: 67395efe129160f5b0b6f3c5701ea5dbac757dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f782095b1452ec44344a3bd0219cafb68d328f25c59ef151e1249693f6f8cf93c329336f946d9683e1084b66a07be88f4eb4bde35f5eb3cc7c6ce850fe90383
|
7
|
+
data.tar.gz: 976a4a455ada5c848a714acbfd1eb3cba94a269a996fe20ca35e3ed7f29328743922a4e153e9f82c3716b359cf3b83fbcbb2509fe2ebb1e53e04b951c024f22c
|
data/README.md
CHANGED
@@ -36,6 +36,9 @@ Here is the rails blog demonstration as appgen description:
|
|
36
36
|
There are comments.
|
37
37
|
A comment has a user.
|
38
38
|
|
39
|
+
Some more descriptions in examples folder.
|
40
|
+
Feel free to contribute with yours!
|
41
|
+
|
39
42
|
### Hosting
|
40
43
|
|
41
44
|
And if you want to host it on heroku, just add:
|
data/appgen.gemspec
CHANGED
data/examples/blogdemo.txt
CHANGED
data/lib/appgen/cli.rb
CHANGED
data/lib/appgen/generator.rb
CHANGED
@@ -1,7 +1,80 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
1
3
|
module Appgen
|
2
4
|
class Generator
|
3
|
-
def self.generate(
|
4
|
-
|
5
|
+
def self.generate(app_description)
|
6
|
+
Generator.new app_description
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(app_description)
|
10
|
+
@app_description = app_description
|
11
|
+
@lines = @app_description.lines
|
12
|
+
@entities = {}
|
13
|
+
find_app_name
|
14
|
+
find_entities
|
15
|
+
find_items
|
16
|
+
generate_app
|
17
|
+
generate_entities
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
KEY_APP_NAME = 'The app name is '
|
23
|
+
KEY_ENTITY = 'There are '
|
24
|
+
KEY_ENTITY_DESCRIPTION = 'A '
|
25
|
+
KEY_ENTITY_SEPARATOR = ' has '
|
26
|
+
KEY_ITEM_DESCRIPTION = 'a '
|
27
|
+
KEY_ITEM_DESCRIPTION_LAST = 'and '
|
28
|
+
|
29
|
+
def find_app_name
|
30
|
+
@lines.each do |line|
|
31
|
+
if line.start_with? KEY_APP_NAME
|
32
|
+
@app_name = line.gsub(KEY_APP_NAME, '').gsub('.', '').chomp
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_entities
|
38
|
+
@lines.each do |line|
|
39
|
+
if line.start_with? KEY_ENTITY
|
40
|
+
entity = line.gsub(KEY_ENTITY, '').gsub('.', '').chomp.singularize
|
41
|
+
@entities[entity] = {}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_items
|
47
|
+
@lines.each do |line|
|
48
|
+
if line.start_with? KEY_ENTITY_DESCRIPTION
|
49
|
+
split = line.gsub(KEY_ENTITY_DESCRIPTION, '').split(KEY_ENTITY_SEPARATOR)
|
50
|
+
entity = split[0]
|
51
|
+
description = split[1]
|
52
|
+
description.split(', ').each do |item|
|
53
|
+
clean_item = item.gsub(KEY_ITEM_DESCRIPTION, '').gsub(KEY_ITEM_DESCRIPTION_LAST, '').gsub('.', '').chomp
|
54
|
+
name = clean_item.split(' ')[0]
|
55
|
+
type = 'string'
|
56
|
+
# TODO other types (text, boolean, float)
|
57
|
+
# TODO references
|
58
|
+
@entities[entity][name] = type
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_app
|
65
|
+
run "rails new #{@app_name} -d postgresql"
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate_entities
|
69
|
+
@entities.each do |key, value|
|
70
|
+
values = value.map { |k, v| "#{k}:#{v}"}.join(' ')
|
71
|
+
run "cd #{@app_name}; rails g scaffold #{key} #{values}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def run(command)
|
76
|
+
puts "$ #{command}"
|
77
|
+
system command
|
5
78
|
end
|
6
79
|
end
|
7
80
|
end
|
data/lib/appgen/loader.rb
CHANGED
@@ -4,7 +4,7 @@ module Appgen
|
|
4
4
|
class Loader
|
5
5
|
def self.load(path=nil)
|
6
6
|
path = find_local_path if path.nil?
|
7
|
-
puts 'No description found, you should add an app description in a file, or call appgen with a path or url.' and return if path.nil?
|
7
|
+
puts ' No description found, you should add an app description in a file, or call appgen with a path or url.' and return if path.nil?
|
8
8
|
read_description path
|
9
9
|
end
|
10
10
|
|
@@ -12,16 +12,14 @@ module Appgen
|
|
12
12
|
Dir['*'].each do |entry|
|
13
13
|
next if File.directory? entry
|
14
14
|
next if entry.start_with? '.'
|
15
|
-
puts "Found file named #{entry}"
|
15
|
+
puts " Found file named #{entry}"
|
16
16
|
return entry
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.read_description(path)
|
21
|
-
puts "Loading app description from #{path}"
|
22
|
-
|
23
|
-
puts app
|
24
|
-
app
|
21
|
+
puts " Loading app description from #{path}"
|
22
|
+
open(path) { |f| f.read }
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/appgen/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- contact@arnaudlevy.com
|