capucine 0.1.7 → 0.2.0

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.
data/lib/settings.rb CHANGED
@@ -1,75 +1,62 @@
1
- module Capucine
2
1
 
3
- class NoUserConfigFile < RuntimeError
4
- end
2
+ module Capucine
5
3
 
6
4
  class Settings
7
- require 'rubygems'
8
- require 'yaml'
5
+ require 'rubygems'
6
+ require 'yaml'
7
+
8
+ attr_accessor :current_dir
9
+ attr_accessor :working_dir
10
+ attr_accessor :external_config
11
+ attr_accessor :project_name
12
+ attr_accessor :root_dir
13
+ attr_accessor :content_dir
14
+ attr_accessor :user_config_file
15
+ attr_accessor :conf
9
16
 
10
- attr_accessor :current_dir, :project_name, :is_usable, :config, :gem_dir, :gem_content_dir, :working_dir, :external_config, :user_config_file
11
17
  def initialize
12
- @current_dir = File.expand_path Dir.pwd
13
- @project_name = 'capucine'
14
- @is_usable = false
15
- @external_config = false
16
- @config = nil
17
- @gem_dir = Gem.loaded_specs[@project_name].full_gem_path
18
- @gem_content_dir = File.join @gem_dir, 'content'
19
-
20
- self.reset_working_dir
18
+
19
+ self.working_dir = File.expand_path(Dir.getwd)
20
+ self.project_name = 'capucine'
21
+ self.root_dir = File.expand_path('../..', __FILE__)
22
+ self.content_dir = File.expand_path('../../content', __FILE__)
23
+
24
+ self.set_user_config_file
25
+ return self
21
26
  end
22
27
 
23
- def get_config user_config_file = nil
24
- @user_config_file = user_config_file
25
- default = File.join @gem_content_dir, "templates", "#{@project_name}.yaml"
26
- @config = YAML::load(File.open(default))
27
-
28
- if user_config_file
29
- from_user = File.expand_path user_config_file
30
- @external_config = true
31
- @working_dir = File.dirname from_user
32
- else
33
- from_user = File.join @working_dir, "#{@project_name}.yaml"
28
+ def set_user_config_file(file = nil, silent = false)
29
+ if not file
30
+ file = File.join self.working_dir, 'capucine.yaml'
31
+ end
32
+
33
+ if File.exist?(file)
34
+ self.user_config_file = File.expand_path(file)
34
35
  end
35
36
 
36
- raise NoUserConfigFile, caller if not File.exist? from_user
37
+ self.get_conf
37
38
 
38
- @is_usable = true
39
- additional = YAML::load(File.open(from_user))
39
+ return self
40
+ end
41
+
42
+ def get_conf
43
+
44
+ default = File.join self.content_dir, "default.yaml"
45
+ self.conf = YAML::load_file(default)
46
+
47
+ if self.user_config_file
48
+ additional = YAML::load_file(self.user_config_file)
49
+ end
40
50
 
41
51
  if additional
42
52
  additional.each do |k, v|
43
- @config[k] = v
53
+ self.conf[k] = v
44
54
  end
45
55
  end
46
- #self.test_config
47
- end
48
56
 
49
- # def test_config
50
- # conf_dirs = []
51
- # dirs = []
52
- # for conf in conf_dirs
53
- # conf = @config[conf]
54
- # dirs.push File.join(@working_dir,conf)
55
- # end
56
-
57
- # for dir in dirs
58
- # unless File.directory?(dir)
59
- # puts "[error] #{dir} - Does not exist."
60
- # exit
61
- # end
62
- # end
63
- # end
64
-
65
- def reset_working_dir
66
- if @external_config
67
- from_user = File.expand_path @user_config_file
68
- @working_dir = File.dirname from_user
69
- else
70
- @working_dir = File.expand_path Dir.pwd
71
- end
57
+ return self
72
58
  end
59
+
73
60
  end
74
61
  end
75
62
 
data/lib/tools.rb CHANGED
@@ -1,50 +1,188 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require 'fileutils'
4
+ require 'open-uri'
5
+ require 'erb'
6
+ require 'npm.rb'
7
+ require 'cdnjs.rb'
8
+
3
9
  module Capucine
4
10
 
5
11
  class Tools
6
- require 'fileutils'
7
- require 'erb'
8
- require "compass-sass.rb"
9
- require "coffeescript.rb"
10
- require "incloudr.rb"
11
12
 
12
- def self.new_project name = nil
13
+ def initialize(capucine)
14
+ @cap = capucine
15
+ end
16
+
17
+ def new_project(scope = nil, name = nil)
18
+ name = name || @cap.settings.project_name # Custom name or 'capucine'
13
19
 
14
- if name
15
- new_project_name = name
16
- else
17
- new_project_name = Capucine.settings.project_name
20
+ @cap.settings.working_dir = File.join @cap.settings.working_dir, name
21
+ self.archive_file(@cap.settings.working_dir)
22
+
23
+ config_file = get_config_file_from_scope(scope)
24
+ files = Dir.glob File.join(@cap.settings.content_dir, 'shared', '**')
25
+
26
+ FileUtils.mkdir @cap.settings.working_dir
27
+ FileUtils.cp_r files, @cap.settings.working_dir
28
+ FileUtils.cp config_file, File.join(@cap.settings.working_dir, 'capucine.yaml')
29
+
30
+ @cap.settings.set_user_config_file(File.join(@cap.settings.working_dir, 'capucine.yaml'))
31
+
32
+ return self
33
+
34
+ end
35
+
36
+ def init(scope = nil, config_or_name = nil)
37
+ self.archive_file(@cap.settings.user_config_file) if @cap.settings.user_config_file
38
+
39
+ # Without Conf
40
+ if not scope and not config_or_name
41
+ file = File.join(@cap.settings.content_dir,'shared', 'capucine.yaml')
42
+ FileUtils.cp file, File.join(@cap.settings.working_dir, 'capucine.yaml')
43
+ return file
44
+ end
45
+
46
+
47
+ # With Conf
48
+ if config_or_name
49
+
50
+ begin
51
+ d = open(config_or_name).read
52
+ rescue
53
+ puts "Error downloading : #{config_or_name}"
54
+ return self
55
+ end
56
+
57
+ file = File.new File.join(@cap.settings.working_dir, 'capucine.yaml'), 'w+'
58
+ file.write(d)
59
+ file.close
60
+ # file.unlink
61
+
62
+ return self
63
+ end
64
+
65
+ if scope
66
+ file = File.join(@cap.settings.root_dir,'templates', "#{scope}.yaml")
67
+ if not File.exists?(file)
68
+ puts "Sorry, this template does not exists : #{scope}"
69
+ return self
70
+ end
71
+
72
+ FileUtils.cp file, File.join(@cap.settings.working_dir, 'capucine.yaml')
73
+
74
+ end
75
+
76
+
77
+ return self
78
+ end
79
+
80
+ def compile(scope = nil)
81
+
82
+ scope = (scope) ? scope : 'all'
83
+ do_things = self.extract_commands_from_scope(scope)
84
+
85
+ do_sass = do_things[0]
86
+ do_coffee = do_things[1]
87
+ do_incloudr = do_things[2]
88
+
89
+ @cap.sass.run_once if do_sass
90
+ @cap.coffee.run_once if do_coffee
91
+ @cap.incloudr.run_once if do_incloudr
92
+
93
+ end
94
+
95
+ def watch(scope = nil)
96
+ self.compile(scope)
97
+
98
+ scope = (scope) ? scope : 'all'
99
+
100
+ do_things = self.extract_commands_from_scope(scope)
101
+
102
+ do_sass = do_things[0]
103
+ do_coffee = do_things[1]
104
+ do_incloudr = do_things[2]
105
+
106
+ thread_sass = @cap.sass.run_watch if do_sass
107
+ thread_coffee = @cap.coffee.run_watch if do_coffee
108
+ # thread_incloudr = @cap.incloudr.run_watch if do_incloudr
109
+
110
+
111
+ thread_sass.join if thread_sass
112
+ thread_coffee.join if thread_coffee
113
+
114
+ end
115
+
116
+ def js(scope, query = nil)
117
+ if scope[0] == 'search'
118
+ if scope[1] == 'npm'
119
+ else
120
+ libs = Capucine::CDNJS.search(query)
121
+ libs.each do |lib|
122
+ puts "#{lib['name']} --- #{lib['version']}"
123
+ end
124
+ end
18
125
  end
19
126
 
20
- Capucine.settings.working_dir = File.join Capucine.settings.current_dir, new_project_name
127
+ if scope[0] == 'list'
128
+ if scope[1] == 'npm'
129
+ else
130
+ libs = Capucine::CDNJS.get_all
131
+ libs.each do |lib|
132
+ puts "#{lib['name']} --- #{lib['version']}"
133
+ end
134
+ end
135
+ end
21
136
 
22
- self.archive_file Capucine.settings.working_dir
23
- FileUtils.mkdir Capucine.settings.working_dir if not File.directory? Capucine.settings.working_dir
137
+ end
24
138
 
25
- self.init files = true
139
+ def update
140
+ system('gem uninstall -a -x capucine')
141
+ system('gem install capucine')
26
142
  end
27
143
 
28
- def self.init all = nil
29
- self.archive_file File.join Capucine.settings.working_dir, 'capucine.yaml'
144
+ def clean
145
+ # TODO
146
+ end
147
+
148
+ #======================
149
+ def extract_commands_from_scope(scope)
150
+ all = ['sass', 'coffee', 'incloudr']
151
+ todo = [false,false,false]
152
+
153
+ scope = (scope != 'all') ? scope.split(',') : all # [] or ['sass', 'coffee']
154
+
155
+ all.each_with_index do |command, i|
156
+ if @cap.settings.conf[command] == true
157
+ if scope.include?(command)
158
+ todo[i] = true
159
+ end
160
+ end
161
+ end
162
+ return todo
163
+
164
+ end
30
165
 
31
- if all
32
- files = Dir.glob File.join(Capucine.settings.gem_content_dir, 'shared', '**')
33
- self.archive_file Capucine.settings.working_dir
34
- FileUtils.cp_r files, Capucine.settings.working_dir
166
+
167
+ def get_config_file_from_scope(scope = nil)
168
+ if not scope
169
+ file = File.join(@cap.settings.content_dir,'shared', 'capucine.yaml')
170
+ elsif scope.match(/^http:\/\//)
171
+ # files = from the web
172
+ else
173
+ # files = from github
35
174
  end
36
175
 
37
- Capucine::Watchr.compile if all
38
- Capucine.settings.reset_working_dir
176
+ return file
39
177
  end
40
178
 
41
- def self.render_template template_file, content = nil
179
+ def render_template template_file, content = nil
42
180
  config = content
43
- template = ERB.new File.new(template_file).read
44
- output = template.result(binding)
181
+ output = ERB.new(File.new(template_file).read).result(binding)
182
+ return output
45
183
  end
46
184
 
47
- def self.archive_file path, force = true
185
+ def archive_file path, force = true
48
186
  return if not File.exist? path
49
187
 
50
188
  is_empty = false
@@ -73,11 +211,9 @@ module Capucine
73
211
 
74
212
  end
75
213
 
76
- def self.clean
77
- FileUtils.rm File.join(Capucine.settings.working_dir, '.compass.rb')
78
- FileUtils.rm_r File.join(Capucine.settings.working_dir, '.incloudr')
79
- end
80
-
81
214
  end
215
+
216
+
217
+
82
218
  end
83
219
 
data/lor ADDED
@@ -0,0 +1,32 @@
1
+
2
+ General
3
+  #init the Capucine
4
+  #init the Capucine with settings
5
+  #init from command line
6
+  #init from command line with sinatra
7
+  #init from command line with wrong template
8
+  #init from command line with distant template (FAILED - 1)
9
+  #new from command line
10
+  #new from command line with custom name
11
+  #new, set coffee, compile
12
+  #new, set coffee, compile with c:sass ONLY
13
+  #new, set coffee, compile with c:coffee ONLY
14
+
15
+ Failures:
16
+
17
+ 1) General#init from command line with distant template
18
+ Failure/Error: @cap.run_command(['i', 'http://capucine.dln.name/capucine.yaml'])
19
+ Errno::ENOENT:
20
+ No such file or directory - /Users/damln/Work/capucine/capucine-gem2/spec/blank/capucine.yaml
21
+  # ./lib/tools.rb:57:in `initialize'
22
+  # ./lib/tools.rb:57:in `open'
23
+  # ./lib/tools.rb:57:in `init'
24
+  # ./lib/capucine.rb:34:in `run_command'
25
+  # ./spec/capucine/capucine_spec.rb:68:in `block (2 levels) in <top (required)>'
26
+
27
+ Finished in 20.63 seconds
28
+ 11 examples, 1 failure
29
+
30
+ Failed examples:
31
+
32
+ rspec ./spec/capucine/capucine_spec.rb:67 # General#init from command line with distant template
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'General' do
4
+
5
+ before :each do
6
+ Dir.chdir("spec/blank")
7
+
8
+ @cap = Capucine::Main.new
9
+ @config_user = File.join @cap.settings.content_dir, 'shared', 'capucine.yaml'
10
+ @config_user_coffee = File.expand_path File.join '..', 'capucine_coffee.yaml'
11
+
12
+ end
13
+
14
+ after :each do
15
+ Dir.chdir("../..")
16
+ end
17
+
18
+ it '#init the Capucine' do
19
+ @cap.should_not eq(nil)
20
+
21
+ @cap.settings.should_not eq(nil)
22
+ @cap.settings.working_dir.should eq(Dir.pwd)
23
+ @cap.settings.conf.should_not eq(nil)
24
+
25
+ end
26
+
27
+ it '#init the Capucine with settings' do
28
+ @cap.settings.set_user_config_file(@config_user)
29
+
30
+ @cap.settings.should_not eq(nil)
31
+ @cap.settings.working_dir.should eq(Dir.pwd)
32
+ @cap.settings.user_config_file.should_not eq(nil)
33
+ @cap.settings.conf.should_not eq(nil)
34
+
35
+ @cap.settings.conf['sass'].should eq(true)
36
+ @cap.settings.conf['coffee'].should eq(false)
37
+ @cap.settings.conf['incloudr'].should eq(false)
38
+ end
39
+
40
+ it '#init from command line' do
41
+ @cap.run_command(['i'])
42
+
43
+ File.exist?('capucine.yaml').should be_true
44
+ size = File.size('capucine.yaml')
45
+ size.should_not == 0
46
+
47
+ FileUtils.rm_r 'capucine.yaml'
48
+ end
49
+
50
+ it '#update from command line' do
51
+ # @cap.run_command(['u'])
52
+ end
53
+
54
+ it '#init from command line with sinatra' do
55
+ @cap.run_command(['i:sinatra'])
56
+
57
+ File.exist?('capucine.yaml').should be_true
58
+
59
+ size = File.size('capucine.yaml')
60
+ size.should_not == 0
61
+
62
+ FileUtils.rm_r 'capucine.yaml'
63
+ end
64
+
65
+ it '#init from command line with wrong template' do
66
+ @cap.run_command(['i:sinatraaaaa'])
67
+
68
+ File.exist?('capucine.yaml').should == false
69
+ end
70
+
71
+ it '#init from command line with distant template' do
72
+ @cap.run_command(['i', 'http://capucine.dln.name/capucine.yaml'])
73
+
74
+ File.exist?('capucine.yaml').should == true
75
+
76
+ size = File.size('capucine.yaml')
77
+ size.should_not == 0
78
+
79
+ FileUtils.rm_r 'capucine.yaml'
80
+ end
81
+
82
+
83
+ it '#new from command line' do
84
+ @cap.run_command(['n'])
85
+
86
+ cap = File.join @cap.settings.working_dir, 'capucine.yaml'
87
+ sass = File.join @cap.settings.working_dir, 'public/css_generated/screen.css'
88
+
89
+ @cap.settings.working_dir.should eq(File.join Dir.pwd, 'capucine')
90
+
91
+ File.exist?(cap).should eq(true)
92
+ File.exist?(sass).should eq(true)
93
+
94
+ FileUtils.rm_r @cap.settings.working_dir
95
+ end
96
+
97
+ it '#new from command line with custom name' do
98
+ @cap.run_command(['n', 'oh_my_god'])
99
+
100
+ cap = File.join @cap.settings.working_dir, 'capucine.yaml'
101
+ sass = File.join @cap.settings.working_dir, 'public/css_generated/screen.css'
102
+
103
+ @cap.settings.working_dir.should eq(File.join Dir.pwd, 'oh_my_god')
104
+
105
+ File.exist?(cap).should eq(true)
106
+ File.exist?(sass).should eq(true)
107
+
108
+ FileUtils.rm_r @cap.settings.working_dir
109
+ end
110
+
111
+
112
+ it '#new, set coffee, compile' do
113
+ @cap.run_command(['n'])
114
+
115
+ Dir.chdir('capucine')
116
+
117
+ @cap.settings.conf['coffee'].should eq(false)
118
+
119
+ @cap.run_command(['c', @config_user_coffee])
120
+
121
+ @cap.settings.user_config_file.should_not eq(nil)
122
+ @cap.settings.conf['coffee'].should eq(true)
123
+
124
+ coffee = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/app.js')
125
+ coffee2 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/app.min.js')
126
+
127
+ File.exist?(coffee).should eq(true)
128
+ File.exist?(coffee2).should eq(true)
129
+
130
+ FileUtils.rm_r @cap.settings.working_dir
131
+ Dir.chdir('..')
132
+
133
+ end
134
+
135
+ it '#new, set coffee, compile with c:sass ONLY' do
136
+ @cap.run_command(['n'])
137
+
138
+ Dir.chdir('capucine')
139
+
140
+ @cap.settings.conf['coffee'].should eq(false)
141
+
142
+ @cap.run_command(['c:sass', @config_user_coffee])
143
+ @cap.settings.conf['coffee'].should eq(true)
144
+
145
+ coffee = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/app.js')
146
+
147
+ File.exist?(coffee).should eq(false)
148
+
149
+ FileUtils.rm_r @cap.settings.working_dir
150
+
151
+ Dir.chdir('..')
152
+
153
+ end
154
+
155
+ it '#new, set coffee, compile with c:coffee ONLY' do
156
+ @cap.run_command(['n'])
157
+
158
+ Dir.chdir('capucine')
159
+
160
+ @cap.settings.conf['coffee'].should eq(false)
161
+
162
+ FileUtils.rm File.expand_path(File.join @cap.settings.working_dir, 'public/css_generated/screen.css')
163
+ @cap.run_command(['c:coffee', @config_user_coffee])
164
+
165
+ @cap.settings.conf['sass'].should eq(true)
166
+ @cap.settings.conf['coffee'].should eq(true)
167
+
168
+ scss = File.expand_path(File.join @cap.settings.working_dir, 'public/css_generated/screen.css')
169
+
170
+ File.exist?(scss).should eq(false)
171
+
172
+ FileUtils.rm_r @cap.settings.working_dir
173
+ Dir.chdir('..')
174
+
175
+ end
176
+
177
+
178
+
179
+ end
@@ -0,0 +1,9 @@
1
+ # require 'spec_helper'
2
+
3
+ # describe '' do
4
+
5
+ # it 'should exist' do
6
+ # cap = Capucine.new
7
+ # cap.should_not be_nil
8
+ # end
9
+ # end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Incloudr' do
4
+
5
+ before :each do
6
+ Dir.chdir("spec/blank")
7
+
8
+ @cap = Capucine::Main.new
9
+ @config_user_incloudr = File.expand_path File.join '..', 'capucine_incloudr.yaml'
10
+ @config_user_incloudr2 = File.expand_path File.join '..', 'capucine_incloudr2.yaml'
11
+ @config_user_incloudr3 = File.expand_path File.join '..', 'capucine_incloudr3.yaml'
12
+
13
+ end
14
+
15
+ after :each do
16
+ Dir.chdir("../..")
17
+ end
18
+
19
+ it '#new, set incloudr, and download jquery from CDNJS' do
20
+ @cap.run_command(['n'])
21
+
22
+ Dir.chdir('capucine')
23
+
24
+ @cap.run_command(['c', @config_user_incloudr])
25
+
26
+ jquery1 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.js')
27
+ jquery2 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.min.js')
28
+
29
+ File.exist?(jquery1).should eq(true)
30
+ File.exist?(jquery2).should eq(true)
31
+
32
+ FileUtils.rm_r @cap.settings.working_dir
33
+ Dir.chdir('..')
34
+
35
+ end
36
+
37
+ it '#new, set incloudr, and download jquery version 1.7 from CDNJS' do
38
+ @cap.run_command(['n'])
39
+
40
+ Dir.chdir('capucine')
41
+
42
+ @cap.run_command(['c', @config_user_incloudr2])
43
+
44
+ jquery1 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.js')
45
+ jquery2 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.min.js')
46
+
47
+ File.exist?(jquery1).should eq(true)
48
+ File.exist?(jquery2).should eq(true)
49
+
50
+ FileUtils.rm_r @cap.settings.working_dir
51
+ Dir.chdir('..')
52
+
53
+ end
54
+
55
+ it '#new, set incloudr, and download jque from CDNJS (error)' do
56
+ @cap.run_command(['n'])
57
+
58
+ Dir.chdir('capucine')
59
+
60
+ @cap.run_command(['c', @config_user_incloudr3])
61
+
62
+ jquery1 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.js')
63
+ jquery2 = File.expand_path(File.join @cap.settings.working_dir, 'public/js_generated/modules/jquery.min.js')
64
+
65
+ File.exist?(jquery1).should eq(false)
66
+ File.exist?(jquery2).should eq(false)
67
+
68
+ FileUtils.rm_r @cap.settings.working_dir
69
+ Dir.chdir('..')
70
+
71
+ end
72
+
73
+ it '#list' do
74
+ @cap.run_command(['js:list'])
75
+ end
76
+
77
+ it '#search' do
78
+ @cap.run_command(['js:search', 'jquery'])
79
+ end
80
+ end
@@ -0,0 +1,30 @@
1
+ sass: true
2
+ coffee: true
3
+ # incloudr: true
4
+
5
+ # # ----------------------------------------
6
+ # sass_images_dir: public/images
7
+ # sass_files_dir: sass
8
+ # sass_output_dir: public/css_generated
9
+ # sass_line_comments: false
10
+ # sass_css_generated_style: expanded # compact | expanded | compressed
11
+ # sass_options: '{:cache => false}'
12
+
13
+ # compass_config: {}
14
+ # compass_plugins:
15
+ # - compass-capucine
16
+
17
+ # sass_import_css: false
18
+ # sass_import_formats: css to sass
19
+ # sass_import_css_dir: public/css/import
20
+ # sass_import_output_dir: sass/converted
21
+
22
+ # coffeescript_bare: false
23
+ # coffeescript_files_dir: coffeescript
24
+ # coffeescript_output_dir: public/js_generated
25
+
26
+ # incloudr_output_dir: public/js_generated/modules
27
+ # incloudr_libs:
28
+ # - jquery
29
+
30
+ # DOCUMENTATION : http:// capucine.dln.name
@@ -0,0 +1,6 @@
1
+ sass: false
2
+ coffee: false
3
+ incloudr: true
4
+
5
+ incloudr_libs:
6
+ - name: jquery
@@ -0,0 +1,8 @@
1
+ sass: false
2
+ coffee: false
3
+ incloudr: true
4
+
5
+ incloudr_libs:
6
+ - name: jquery
7
+ version: 1.7
8
+