bloc 0.0.5 → 0.0.6
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/CHANGELOG.md +8 -0
- data/bin/bloc +15 -3
- data/lib/bloc.rb +1 -0
- data/lib/bloc/command.rb +6 -1
- data/lib/bloc/command/generate.rb +12 -0
- data/lib/bloc/command/validate.rb +11 -27
- data/lib/bloc/hash_constructed.rb +5 -0
- data/lib/bloc/manifest.rb +52 -0
- data/lib/bloc/models.rb +18 -0
- data/lib/bloc/to_hash.rb +9 -0
- data/lib/bloc/version.rb +1 -1
- metadata +17 -12
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.0.6
|
2
|
+
|
3
|
+
* manifest class, plus Course and Chapter models
|
4
|
+
* "bloc generate" command
|
5
|
+
* parse returns a manifest instance
|
6
|
+
* to_h mixin for course and chapter
|
7
|
+
* hash_constructed mixin for course and chapter constructors
|
8
|
+
|
1
9
|
### 0.0.5
|
2
10
|
|
3
11
|
* patch verification no longer interferes with your git history (or cares about it)
|
data/bin/bloc
CHANGED
@@ -4,12 +4,24 @@ require "rubygems"
|
|
4
4
|
require "bundler/setup"
|
5
5
|
require "bloc"
|
6
6
|
|
7
|
-
|
7
|
+
commands = {
|
8
|
+
'validate' => proc { Bloc::Command::Validate.run },
|
9
|
+
'generate' => proc { Bloc::Command::Generate.run }
|
10
|
+
}
|
11
|
+
if ARGV.length == 1 && commands.keys.include?(ARGV.first.downcase)
|
8
12
|
begin
|
9
|
-
|
13
|
+
commands[ARGV.first.downcase].call
|
10
14
|
rescue => e
|
11
15
|
puts e
|
12
16
|
end
|
13
17
|
else
|
14
|
-
|
18
|
+
helpstring = <<-eos
|
19
|
+
Usage:
|
20
|
+
bloc <command> [options]
|
21
|
+
|
22
|
+
Commands:
|
23
|
+
validate
|
24
|
+
generate ["Course name"]
|
25
|
+
eos
|
26
|
+
puts helpstring
|
15
27
|
end
|
data/lib/bloc.rb
CHANGED
data/lib/bloc/command.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Bloc
|
2
|
+
module Command
|
3
|
+
class Generate
|
4
|
+
def self.run(*args)
|
5
|
+
course = Bloc::Models::Course.new(:name => "My course", :description => "")
|
6
|
+
chapters = []
|
7
|
+
manifest = Bloc::Manifest.new({"course" => course, "chapters" => chapters})
|
8
|
+
manifest.write
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module Bloc
|
2
2
|
module Command
|
3
3
|
class Validate
|
4
|
-
MANIFEST_NOT_FOUND = "Unable to find Bloc Manifest in bloc/bloc_manifest.json".red
|
5
|
-
MANIFEST_PATH = File.join("bloc", "bloc_manifest.json")
|
6
|
-
INVALID_MANIFEST = "Invalid JSON in Bloc Manifest: #{MANIFEST_PATH}".red
|
7
|
-
VALID_MANIFEST = "Valid Bloc Manifest".green
|
8
4
|
NO_DEFAULT_COURSE_FILE = "No default file for course specified (OK)".green
|
9
5
|
VALID_DEFAULT_COURSE_FILE = "Default file for course exists (OK)".green
|
10
6
|
INVALID_DEFAULT_COURSE_FILE = "Default file for course does not exist (expected %s)".red
|
@@ -14,27 +10,15 @@ module Bloc
|
|
14
10
|
NO_SUCH_PATCH = "Patch not found: %s".red
|
15
11
|
|
16
12
|
def self.run(*args)
|
17
|
-
manifest =
|
13
|
+
manifest = Manifest.parse
|
18
14
|
check_course_default_file manifest
|
19
15
|
check_chapter_default_files manifest
|
20
16
|
check_patches manifest
|
21
17
|
end
|
22
18
|
|
23
|
-
def self.parse_manifest
|
24
|
-
raise MANIFEST_NOT_FOUND unless File.exists?(MANIFEST_PATH)
|
25
|
-
manifest_raw = File.read(MANIFEST_PATH)
|
26
|
-
|
27
|
-
begin
|
28
|
-
manifest = JSON.parse(manifest_raw)
|
29
|
-
puts VALID_MANIFEST
|
30
|
-
rescue
|
31
|
-
raise INVALID_MANIFEST
|
32
|
-
end
|
33
|
-
manifest
|
34
|
-
end
|
35
19
|
|
36
20
|
def self.check_course_default_file(manifest)
|
37
|
-
course_default_file = manifest
|
21
|
+
course_default_file = manifest.course.default_file
|
38
22
|
if course_default_file.nil?
|
39
23
|
puts NO_DEFAULT_COURSE_FILE
|
40
24
|
else
|
@@ -47,14 +31,14 @@ module Bloc
|
|
47
31
|
end
|
48
32
|
|
49
33
|
def self.check_chapter_default_files(manifest)
|
50
|
-
manifest
|
51
|
-
if chapter
|
52
|
-
puts NO_DEFAULT_CHAPTER_FILE % chapter
|
34
|
+
manifest.chapters.each do |chapter|
|
35
|
+
if chapter.default_file.nil?
|
36
|
+
puts NO_DEFAULT_CHAPTER_FILE % chapter.name
|
53
37
|
else
|
54
|
-
if File.exists? chapter
|
55
|
-
puts VALID_DEFAULT_CHAPTER_FILE % chapter
|
38
|
+
if File.exists? chapter.default_file
|
39
|
+
puts VALID_DEFAULT_CHAPTER_FILE % chapter.name
|
56
40
|
else
|
57
|
-
raise INVALID_DEFAULT_CHAPTER_FILE % [chapter
|
41
|
+
raise INVALID_DEFAULT_CHAPTER_FILE % [chapter.name, chapter.default_file]
|
58
42
|
end
|
59
43
|
end
|
60
44
|
end
|
@@ -67,14 +51,14 @@ module Bloc
|
|
67
51
|
`git init`
|
68
52
|
`git add .`
|
69
53
|
`git commit -m "initial"`
|
70
|
-
manifest
|
71
|
-
patch = chapter
|
54
|
+
manifest.chapters.each do |chapter|
|
55
|
+
patch = chapter.patch
|
72
56
|
unless patch.nil? # technically this should be validated earlier
|
73
57
|
unless File.exists?("bloc/#{patch}")
|
74
58
|
raise NO_SUCH_PATCH % patch
|
75
59
|
end
|
76
60
|
puts `patch < bloc/#{patch}`
|
77
|
-
puts `#{chapter
|
61
|
+
puts `#{chapter.command}`
|
78
62
|
end
|
79
63
|
end
|
80
64
|
rescue Exception => e
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "bloc/hash_constructed.rb"
|
2
|
+
require "bloc/models.rb"
|
3
|
+
|
4
|
+
module Bloc
|
5
|
+
class Manifest
|
6
|
+
MANIFEST_NOT_FOUND = "Unable to find Bloc Manifest in bloc/bloc_manifest.json".red
|
7
|
+
MANIFEST_PATH = File.join("bloc", "bloc_manifest.json")
|
8
|
+
INVALID_MANIFEST = "Invalid JSON in Bloc Manifest: #{MANIFEST_PATH}".red
|
9
|
+
VALID_MANIFEST = "Valid Bloc Manifest".green
|
10
|
+
|
11
|
+
attr_accessor :course, :chapters
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@course = options["course"]
|
15
|
+
@chapters = options["chapters"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def write
|
19
|
+
File.open(MANIFEST_PATH, "w") do |file|
|
20
|
+
file.write(JSON.pretty_generate(to_h))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_h
|
25
|
+
hash = {}
|
26
|
+
hash["course"] = @course.to_h
|
27
|
+
hash["chapters"] = []
|
28
|
+
@chapters.each do |chapter|
|
29
|
+
hash["chapters"] << chapter.to_h
|
30
|
+
end
|
31
|
+
hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse
|
35
|
+
raise MANIFEST_NOT_FOUND unless File.exists?(MANIFEST_PATH)
|
36
|
+
manifest_raw = File.read(MANIFEST_PATH)
|
37
|
+
|
38
|
+
begin
|
39
|
+
manifest = JSON.parse(manifest_raw)
|
40
|
+
puts VALID_MANIFEST
|
41
|
+
rescue
|
42
|
+
raise INVALID_MANIFEST
|
43
|
+
end
|
44
|
+
course = Bloc::Models::Course.new(manifest["course"])
|
45
|
+
chapters = []
|
46
|
+
manifest["chapters"].each do |chapter|
|
47
|
+
chapters << Bloc::Models::Chapter.new(chapter)
|
48
|
+
end
|
49
|
+
Manifest.new({"course" => course, "chapters" => chapters})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/bloc/models.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bloc/hash_constructed.rb'
|
2
|
+
require 'bloc/to_hash.rb'
|
3
|
+
|
4
|
+
module Bloc
|
5
|
+
module Models
|
6
|
+
class Course
|
7
|
+
include HashConstructed
|
8
|
+
include ToHash
|
9
|
+
attr_accessor :name, :description, :default_file
|
10
|
+
end
|
11
|
+
|
12
|
+
class Chapter
|
13
|
+
include HashConstructed
|
14
|
+
include ToHash
|
15
|
+
attr_accessor :name, :command, :markdown, :default_file, :patch, :cursor_row, :cursor_column
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/bloc/to_hash.rb
ADDED
data/lib/bloc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-05 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70226654954220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70226654954220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: fakefs
|
28
|
-
requirement: &
|
28
|
+
requirement: &70226654953800 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70226654953800
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: ruby-debug19
|
39
|
-
requirement: &
|
39
|
+
requirement: &70226654953380 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70226654953380
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: json
|
50
|
-
requirement: &
|
50
|
+
requirement: &70226654952960 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70226654952960
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: colorize
|
61
|
-
requirement: &
|
61
|
+
requirement: &70226654952540 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70226654952540
|
70
70
|
description: A command-line tool for Bloc
|
71
71
|
email:
|
72
72
|
- roshan.choxi@gmail.com
|
@@ -86,7 +86,12 @@ files:
|
|
86
86
|
- bloc.gemspec
|
87
87
|
- lib/bloc.rb
|
88
88
|
- lib/bloc/command.rb
|
89
|
+
- lib/bloc/command/generate.rb
|
89
90
|
- lib/bloc/command/validate.rb
|
91
|
+
- lib/bloc/hash_constructed.rb
|
92
|
+
- lib/bloc/manifest.rb
|
93
|
+
- lib/bloc/models.rb
|
94
|
+
- lib/bloc/to_hash.rb
|
90
95
|
- lib/bloc/version.rb
|
91
96
|
- spec/command/validate_spec.rb
|
92
97
|
- spec/spec_helper.rb
|