gennifer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b390b63431b9a9590f77476e017eadda618c298
4
- data.tar.gz: 9d8f030b3bbee88353846b0676429dd19029704e
3
+ metadata.gz: ff35e3df1f794dec0816d0842cb897efae5d4850
4
+ data.tar.gz: 057739a7c096baf25645f5b28d13c3167c60b939
5
5
  SHA512:
6
- metadata.gz: 585a1c2d17551a99c07aa25f4753fa03770ac5fd24e437c778b89e15a22f6c919f093e7c1a872917bf0b5512f06484d5a969e979469c9e6cdb9e0f026ce4b8fd
7
- data.tar.gz: 414118f1af6f21383b543163c68976519aa726e29979274c5dc6c4978b929779b5d9151105a0f988e02681c6b74c16bcd2445c396e3f9b0ac1de1ef21a925edb
6
+ metadata.gz: 5586c6bd0864224a559874b1c21afb3573ae47469df1549ed6c1ae2c7da25ac09ca749180f9b85e944fa478256d8313a39866a5d141f0237829e07f8a706d96a
7
+ data.tar.gz: 0c45264f82d24d98bf8b8fecd7a6a165fa1a34e221f93bdc70c77f81784b16800220eb6a8429df6e9da17397612f450c7feadcd5a9975f3c27476bf16abaf49d
data/.gitignore CHANGED
@@ -7,3 +7,27 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /private/
11
+
12
+ *.log
13
+ *.7z
14
+ *.dmg
15
+ *.gz
16
+ *.iso
17
+ *.jar
18
+ *.rar
19
+ *.tar
20
+ *.zip
21
+ *.sql
22
+ *.sqlite
23
+ *.com
24
+ *.class
25
+ *.dll
26
+ *.exe
27
+ .DS_Store
28
+ .DS_Store?
29
+ ._*
30
+ .Spotlight-V100
31
+ .Trashes
32
+ ehthumbs.db
33
+ Thumbs.db
data/exe/gen ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gennifer"
4
+
5
+ Gennifer::gen(ARGV)
@@ -1,3 +1,3 @@
1
1
  module Gennifer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/gennifer.rb CHANGED
@@ -1,5 +1,139 @@
1
1
  require "gennifer/version"
2
+ require 'fileutils'
3
+ require 'erb'
4
+
5
+ # TODO: command to generate new recipes with commented hint/tutorial
6
+ # TODO: write tests and test in windows
7
+ # TODO: better treatment for duplicate files in bin folder
8
+ # TODO: put help text in recipe and make the help command auto read it
2
9
 
3
10
  module Gennifer
4
- # Your code goes here...
11
+ def self.gen(argv)
12
+
13
+ argv0 = argv[0] || ''
14
+ argv1 = argv[1] || ''
15
+
16
+ if (argv0 == 'install' && (Dir.exists?(File.expand_path('~/.gennifer'))==true)) then
17
+ puts "
18
+ It seems that you have already installed Gennifer before since ~/.gennifer exists.
19
+
20
+ If you insist, please backup your custom recipes, resources, and settings (all the contents in ~/.gennifer). Then remove the folder ~/.gennifer and re-run 'gen install'.
21
+
22
+ "
23
+ return
24
+ elsif (argv0 == 'forcedinstall') then
25
+ FileUtils.rm_rf(File.expand_path('~/.gennifer'))
26
+ install_gennifer
27
+ return
28
+ end
29
+
30
+ if (Dir.exists?(File.expand_path('~/.gennifer'))==false) then
31
+ install_gennifer
32
+ end
33
+
34
+ require File.expand_path('~/.gennifer/settings.rb', __FILE__)
35
+ Dir[File.expand_path('~/.gennifer/recipes/**/*.rb')].each {|file| require file }
36
+
37
+
38
+ if (argv0 == 'help' or argv0 == '') then
39
+ help_text(argv1)
40
+ else
41
+ recipe_class = get_recipe_class(argv1)
42
+ if recipe_class then
43
+ use_recipe(recipe_class,argv0,argv)
44
+ else
45
+ recipe_class = get_recipe_class_from_path(argv0)
46
+ if recipe_class then
47
+ use_recipe(recipe_class,argv0,argv)
48
+ elsif Settings::USEDEFAULT == true then
49
+ use_recipe(DefaultRecipe,argv0,argv)
50
+ else
51
+ puts "Recipe not found"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def self.get_recipe_class_from_path(full_name)
58
+ original_name = File.basename(full_name)
59
+ ext_name_list = File.basename(full_name).split('.')
60
+ base_name = ext_name_list.delete_at(0)
61
+ combined_ext_name = ext_name_list.join('_')
62
+ trial_list = [original_name] + [combined_ext_name] + ext_name_list + [base_name]
63
+
64
+ trial_list.each do |trial|
65
+ recipe_class = get_recipe_class(trial)
66
+ if recipe_class then
67
+ return recipe_class
68
+ end
69
+ end
70
+
71
+ return nil
72
+ end
73
+
74
+ def self.use_recipe(recipe_class, full_name, argv)
75
+
76
+ if recipe_class then
77
+ require File.expand_path('../recipe_helper.rb', __FILE__)
78
+ recipe_setup(recipe_class)
79
+ jr = recipe_class.new(File.expand_path('./'+ full_name ), argv)
80
+ jr.generate
81
+ end
82
+ return recipe_class
83
+ end
84
+
85
+ def self.help_text(argv1)
86
+
87
+ if argv1 == 'install' then
88
+ puts "
89
+ gen install install the default settings and recipe
90
+ "
91
+ elsif argv1 == 'article' then
92
+ puts "
93
+ gen myproject article generate a latex article project
94
+ "
95
+ elsif argv1 == 'exam' then
96
+ puts "
97
+ gen myproject exam generate a latex exam project
98
+ "
99
+ elsif argv1 == 'exe' then
100
+ puts "
101
+ gen myfile.rb exe generate a ruby file and make it executable
102
+ "
103
+ elsif argv1 == 'bin' then
104
+ puts "
105
+ gen myfile.rb bin generate a ruby file and make it executable,
106
+ move the file to the bin folder and use the
107
+ editor to open the file.
108
+ "
109
+ else
110
+ puts "
111
+ gen install install the default settings and recipe
112
+ gen myproject article generate a latex article project
113
+ gen myproject exam generate a latex exam project
114
+ gen myproject letter generate a latex letter project
115
+ gen myfile.rb generate a ruby file with name myfile.rb
116
+ gen myfile rb generate a ruby file with name myfile
117
+ gen myfile.rb exe generate a ruby file and make it executable
118
+ gen myfile.rb bin generate a ruby file and make it executable,
119
+ move the file to the bin folder and use the
120
+ editor to open the file.
121
+ "
122
+ end
123
+ end
124
+
125
+ def self.install_gennifer
126
+ FileUtils.mkdir_p(File.expand_path('~/.gennifer'))
127
+ FileUtils.cp_r(Dir[File.expand_path('../../default/*', __FILE__)], File.expand_path('~/.gennifer'))
128
+ puts "Gennifer default settings installed"
129
+ end
130
+
131
+ def self.get_recipe_class(recipe_text)
132
+ begin
133
+ recipe_class = Object.const_get(recipe_text.capitalize.gsub(/_(.)/) {|e| $1.upcase} + "Recipe")
134
+ rescue
135
+ # puts "Recipe not found"
136
+ end
137
+ recipe_class
138
+ end
5
139
  end
@@ -0,0 +1,76 @@
1
+ def recipe_setup(jr)
2
+ jr.class_eval do
3
+ def initialize(full_path, argv)
4
+ @argv = argv
5
+ @current_dir = Dir.pwd
6
+ @resources = File.expand_path('~/.jennifer/resources')
7
+ @full_name = File.basename(full_path)
8
+ @base_name = File.basename(full_path,'.*')
9
+ @ext_name = File.extname(full_path)
10
+ @recipe = self.class
11
+ @target_dir = File.expand_path('./'+ full_path + '/..')
12
+ #@project_dir = File.expand_path('./'+ full_path )
13
+ @full_path = full_path
14
+ end
15
+
16
+ def generate
17
+ if File.exists?(@full_path)
18
+ puts(@full_path + ' already exists.')
19
+ else
20
+ invoke(BeforeRecipe)
21
+ recipe
22
+ invoke(AfterRecipe)
23
+ end
24
+ end
25
+
26
+ def create(target, resource=nil)
27
+ if resource.nil?
28
+ FileUtils.mkdir_p(File.expand_path(target))
29
+ else
30
+ FileUtils.cp_r(File.expand_path("#{@resources}/#{resource}"),File.expand_path(target))
31
+ end
32
+ puts "Create #{File.expand_path(target)}" if Settings::VERBOSE
33
+ end
34
+
35
+ # def file(target, resource=nil)
36
+ # if resource.nil?
37
+ # FileUtils.touch(File.expand_path(target))
38
+ # else
39
+ # FileUtils.cp_r(File.expand_path("#{@resources}/#{resource}"),File.expand_path(target))
40
+ # end
41
+ # puts "Create #{File.expand_path(target)}" if Settings::VERBOSE
42
+ # end
43
+ #
44
+ # def directory(target, resource=nil)
45
+ # if resource.nil?
46
+ # FileUtils.mkdir_p(File.expand_path(target))
47
+ # else
48
+ # FileUtils.cp_r(File.expand_path("#{@resources}/#{resource}"),File.expand_path(target))
49
+ # end
50
+ # puts "Create #{File.expand_path(target)}" if Settings::VERBOSE
51
+ # end
52
+
53
+ def invoke(invoke_class)
54
+ recipe_setup(invoke_class)
55
+ new_recipe = invoke_class.new(@full_path, @argv)
56
+ new_recipe.recipe
57
+ end
58
+
59
+ def check_argv(check)
60
+ if @argv.include?(check) then
61
+ return true
62
+ else
63
+ return false
64
+ end
65
+ end
66
+
67
+ def executable(file)
68
+ FileUtils.chmod 0755, file
69
+ end
70
+
71
+ def erb(full_path)
72
+ erb = File.read(full_path)
73
+ File.open(full_path, 'w') { |file| file.write(ERB.new(erb,0,'-').result(binding)) }
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gennifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chungsang Tom Lam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-16 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,7 +42,8 @@ description: 'This is a gem for generating files/projects using recipes. The def
42
42
  recipes included ruby python and latex files. Erb template supported. '
43
43
  email:
44
44
  - erinata@gmail.com
45
- executables: []
45
+ executables:
46
+ - gen
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -55,9 +56,11 @@ files:
55
56
  - Rakefile
56
57
  - bin/console
57
58
  - bin/setup
59
+ - exe/gen
58
60
  - gennifer.gemspec
59
61
  - lib/gennifer.rb
60
62
  - lib/gennifer/version.rb
63
+ - lib/recipe_helper.rb
61
64
  homepage: https://github.com/erinata/gennifer
62
65
  licenses:
63
66
  - All rights reserved