lessons_indexer 1.0.3 → 1.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: 9cf9dd26d4596d4b4fe904c7e1cfa6989a89de64
4
- data.tar.gz: b6e93014db8823c91920027df9a5c2884554a3ec
3
+ metadata.gz: f793d2c80b4ec88c038e6a62cd5fd370bda0eeff
4
+ data.tar.gz: 04f95e63497298e61a3a9c0c024acc294cbab813
5
5
  SHA512:
6
- metadata.gz: 98cffc5c91e39187dfc5cde41e3a18b76d4709d8a69d781f0e058082a4fa8de141f47a00256b1641d9fdbfe6b02b11f18937e8c2a4664e71dec6cdaa9c802785
7
- data.tar.gz: 4407bfebba3ec618c353d92db5c817e03313d6fe22b09e964a8cc3f79223eed71725e7ba52b67e2b6d4cb5a1e6388a777dd420c5d38b8a0bc0c5fdaf08ca6615
6
+ metadata.gz: 906f130d13874fb3723307e82920fa53fdf0de25614e0ae6a9a54b01c4ac85390d6f9173cf96f7156ffc28f3e39499079055e9fb6ab34a602665ed96ac260a2d
7
+ data.tar.gz: e222988ff131ff03152a46a53482467cc10ef76a1d80f56e3b977001b7bbd5affd49ecfb5d052de7503b42295d5065bbda7ae9d0439d5a4153e6259493166d19
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.5
6
6
  - 2.2.2
7
+ - 2.3.0
7
8
  - rbx
8
9
 
9
10
  install: bundle install --retry=3
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Dependency Status](https://gemnasium.com/bodrovis/lessons_indexer.svg)](https://gemnasium.com/bodrovis/lessons_indexer)
6
6
  # Lessons Indexer for Sitepoint Premium
7
7
 
8
- Builds an index in Markdown format for the lesson files in the provided directory, adds heading images to the files, generates PDFs from Markdown, pushes changes to GitHub. Can work with multiple branches.
8
+ Builds an index in Markdown format for the lesson files in the provided directory, adds heading images to the files, generates PDFs from Markdown, pushes changes to GitHub. Can work with multiple branches and generate an array of empty files.
9
9
 
10
10
  Relies on [messages_dictionary](https://github.com/bodrovis-learning/messages_dictionary) to store messages.
11
11
 
@@ -54,6 +54,14 @@ has a heading in the beginning, it will be skipped.
54
54
  Defaults to `headings`, has no effect if the `-i` flag is not set.
55
55
  * `-f` (`--pdf`) - should PDFs be generated from the lesson files in markdown format. PDFs will have the same name as the
56
56
  lesson files, read more [below](#pdf-generation). Defauls to `false`.
57
+ * `-l` (`--lessons`) - accepts an array of numbers delimited with `,` (for example, `-l 1,2,3`). Each number represents a number
58
+ of files to generate for a specific lesson. In the provided example, the first lesson contains 1 step, the second -
59
+ 2 steps, the third - 3 steps. The script will then create a bunch of appropriate files, called *lessonx-y.md*,
60
+ where *x* is a lesson number and *y* is a step number, for example *lesson1-1.md*, *lesson2-1.md* etc, up to *lesson3-3.md*. This option
61
+ is useful when you only begin to produce handouts for a course and need a bunch of empty files to place your text into.
62
+ **Please note** that if this option is present, all other options (expect for the `--path`) will be ignored,
63
+ meaning that the script won't do anything else. This is because the lesson files will be empty and
64
+ obviously you wouldn't want to generate PDFs or push anything to GitHub at this point.
57
65
 
58
66
  ## Some Assumptions
59
67
 
@@ -64,7 +72,7 @@ the course and end with the `_handouts` (the program will do its best to convert
64
72
  be converted to "Introduction To Less").
65
73
  * Lesson files should have the lesson and step numbers in their title separated by `.` or `-`. It may contain any other
66
74
  words, but they have to have *.md* extension. Here is an example of a valid file name: `lesson3.2.md` or `h3-2.md`. All other
67
- files will be ignored.
75
+ files will be ignored. Use `-l` option to generate lesson files automatically.
68
76
  * If the `-i` flag is set (to add headings to the lesson files), the `*_handouts` folder has to contain directory with the images.
69
77
  This directory's name can be provided with the `-d` flag. Files inside should follow the same naming conditions as for the lesson
70
78
  files (of course, they don't need to have the *.md* extension). Valid files names: `Git Course 1.1.jpg` or `google_maps10-3.png`.
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "slop", "~> 4.2"
21
21
  spec.add_dependency "facets", "~> 3.0"
22
22
  spec.add_dependency "colorize", "~> 0.7.7"
23
- spec.add_dependency "messages_dictionary", "~> 0.1.0"
23
+ spec.add_dependency "messages_dictionary", "~> 0.1.2"
24
24
 
25
25
  spec.add_development_dependency "rake", "~> 11.1"
26
26
  spec.add_development_dependency "rspec", "~> 3.4"
@@ -10,7 +10,7 @@ module LessonsIndexer
10
10
  end
11
11
 
12
12
  def each
13
- list.map { |heading| yield heading }
13
+ list.map { |element| yield element }
14
14
  end
15
15
  end
16
16
  end
@@ -12,6 +12,16 @@ module LessonsIndexer
12
12
  @headings = []
13
13
  end
14
14
 
15
+ def generate_files(lessons_count)
16
+ within(dir, true) do
17
+ lessons_count.map {|l| Integer(l)}.each_with_index do |steps, lesson|
18
+ (1..steps).each do |step|
19
+ File.new("lesson#{lesson + 1}-#{step}.md", 'w+').close
20
+ end
21
+ end
22
+ end
23
+ end
24
+
15
25
  def generate_index
16
26
  lessons.list.sort.inject(pou('course.index_title', title: title)) do |memo, lesson|
17
27
  memo + lesson.link(dir)
@@ -12,10 +12,20 @@ module LessonsIndexer
12
12
  def do_work!
13
13
  course = Course.new(get_course_dir, options.headings_dir)
14
14
 
15
- build_index(course) unless options.skip_index
16
- add_headings(course) if options.headings
17
- generate_pdfs(course) if options.pdf
18
- git_push! if options.git
15
+ if options.lessons.length > 0
16
+ generate_files(course)
17
+ else
18
+ build_index(course) unless options.skip_index
19
+ add_headings(course) if options.headings
20
+ generate_pdfs(course) if options.pdf
21
+ git_push! if options.git
22
+ end
23
+ end
24
+
25
+ def generate_files(course)
26
+ with_messages(pou('lessons.starting'), pou('lessons.done', title: course.title)) do
27
+ course.generate_files(options.lessons)
28
+ end
19
29
  end
20
30
 
21
31
  def build_index(course)
@@ -1,6 +1,9 @@
1
1
  starter:
2
2
  welcome: "=== [ Welcome to Lessons Indexer ver{{version}}! ] ==="
3
3
  done: "=== [ DONE. ] ==="
4
+ lessons:
5
+ starting: "Starting to generate files..."
6
+ done: "Lesson files for the {{title}} course are generated!"
4
7
  index:
5
8
  starting: "Starting to build index..."
6
9
  done: "Index for the {{title}} course is generated!"
@@ -30,4 +33,5 @@ options:
30
33
  all: 'Work with all branches (except for master)'
31
34
  headings: 'Add heading images to the beginning of the lesson files?'
32
35
  headings_dir: 'Relative path to the directory with heading images'
33
- pdf: 'Should PDFs be generated?'
36
+ pdf: 'Should PDFs be generated?'
37
+ lessons: 'Lessons'
@@ -26,6 +26,7 @@ module LessonsIndexer
26
26
  o.bool '-i', '--headings', pou('options.headings'), default: false
27
27
  o.string '-d', '--headings_dir', pou('options.headings_dir'), default: pou('options.default.headings_dir')
28
28
  o.bool '-f', '--pdf', pou('options.pdf'), default: false
29
+ o.array '-l', '--lessons', pou('options.lessons'), default: []
29
30
  o.on '--help' do
30
31
  puts o
31
32
  exit
@@ -1,3 +1,3 @@
1
1
  module LessonsIndexer
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
data/spec/course_spec.rb CHANGED
@@ -26,6 +26,10 @@ RSpec.describe LessonsIndexer::Course do
26
26
  expect(subject).to respond_to(:generate_pdfs)
27
27
  end
28
28
 
29
+ specify "#generate_files" do
30
+ expect(subject).to respond_to(:generate_files)
31
+ end
32
+
29
33
  context "#generate_headings" do
30
34
  it "should return formatted heading and path to file" do
31
35
  expect(subject).to receive(:lessons).and_return(sample_lessons)
@@ -54,9 +58,9 @@ RSpec.describe LessonsIndexer::Course do
54
58
  end
55
59
 
56
60
  context "file system access" do
57
- before(:all) { setup_env! }
61
+ before(:each) { setup_env! }
58
62
 
59
- after(:all) { clear_env! }
63
+ after(:each) { clear_env! }
60
64
 
61
65
  context "#load_headings!" do
62
66
  let(:headings) {subject.load_headings!}
data/spec/indexer_spec.rb CHANGED
@@ -1,90 +1,134 @@
1
1
  RSpec.describe LessonsIndexer::Indexer do
2
- before(:all) { setup_env! }
3
- after(:all) { clear_env! }
4
-
5
2
  subject { described_class.new(LessonsIndexer::Options.new(sample_options)) }
6
3
  let(:course) {LessonsIndexer::Course.new(subject.get_course_dir, subject.options.headings_dir)}
7
4
 
8
- context "#options" do
9
- it "should return output" do
10
- expect(subject.options.output).to eq('test.md')
11
- end
12
- end
5
+ context "with pre-defined files" do
6
+ before(:all) { setup_env! }
7
+ after(:all) { clear_env! }
13
8
 
14
- context "#do_work!" do
15
- it "should build index if --skip_index is not set" do
16
- expect(subject).to receive(:build_index)
17
- expect(subject).not_to receive(:add_headings)
18
- expect(subject).not_to receive(:git_push!)
19
- capture_stdout { subject.do_work! }
9
+ context "#options" do
10
+ it "should return output" do
11
+ expect(subject.options.output).to eq('test.md')
12
+ end
20
13
  end
21
14
 
22
- it "should add headings if --headings is set" do
23
- allow(subject.options).to receive(:skip_index).and_return(true)
24
- allow(subject.options).to receive(:headings).and_return(true)
25
- expect(subject).to receive(:add_headings)
26
- expect(subject).not_to receive(:build_index)
27
- expect(subject).not_to receive(:git_push!)
28
- capture_stdout { subject.do_work! }
29
- end
15
+ context "#do_work!" do
16
+ it "should build index if --skip_index is not set", :test do
17
+ expect(subject).to receive(:build_index)
18
+ expect(subject).not_to receive(:add_headings)
19
+ expect(subject).not_to receive(:git_push!)
20
+ capture_stdout { subject.do_work! }
21
+ end
30
22
 
31
- it "should push to github if --git is set" do
32
- allow(subject.options).to receive(:skip_index).and_return(true)
33
- allow(subject.options).to receive(:git).and_return(true)
34
- expect(subject).to receive(:git_push!)
35
- expect(subject).not_to receive(:build_index)
36
- expect(subject).not_to receive(:add_headings)
37
- capture_stdout { subject.do_work! }
38
- end
23
+ it "should generate files if --lessons is set" do
24
+ allow(subject.options).to receive(:lessons).and_return([1,2])
25
+ expect(subject).to receive(:generate_files)
26
+ expect(subject).not_to receive(:add_headings)
27
+ expect(subject).not_to receive(:git_push!)
28
+ expect(subject).not_to receive(:generate_pdfs)
29
+ expect(subject).not_to receive(:build_index)
30
+ capture_stdout { subject.do_work! }
31
+ end
39
32
 
40
- it "should generate pdfs if --pdf is set" do
41
- allow(subject.options).to receive(:skip_index).and_return(true)
42
- allow(subject.options).to receive(:pdf).and_return(true)
43
- expect(subject).to receive(:generate_pdfs)
44
- capture_stdout { subject.do_work! }
33
+ it "should add headings if --headings is set" do
34
+ allow(subject.options).to receive(:skip_index).and_return(true)
35
+ allow(subject.options).to receive(:headings).and_return(true)
36
+ expect(subject).to receive(:add_headings)
37
+ expect(subject).not_to receive(:build_index)
38
+ expect(subject).not_to receive(:git_push!)
39
+ capture_stdout { subject.do_work! }
40
+ end
41
+
42
+ it "should push to github if --git is set" do
43
+ allow(subject.options).to receive(:skip_index).and_return(true)
44
+ allow(subject.options).to receive(:git).and_return(true)
45
+ expect(subject).to receive(:git_push!)
46
+ expect(subject).not_to receive(:build_index)
47
+ expect(subject).not_to receive(:add_headings)
48
+ capture_stdout { subject.do_work! }
49
+ end
50
+
51
+ it "should generate pdfs if --pdf is set" do
52
+ allow(subject.options).to receive(:skip_index).and_return(true)
53
+ allow(subject.options).to receive(:pdf).and_return(true)
54
+ expect(subject).to receive(:generate_pdfs)
55
+ capture_stdout { subject.do_work! }
56
+ end
45
57
  end
46
- end
47
58
 
48
- context "#get_course_dir" do
49
- it "should return course dir" do
50
- expect(subject.get_course_dir).to eq('my_course_handouts')
59
+ context "#get_course_dir" do
60
+ it "should return course dir" do
61
+ expect(subject.get_course_dir).to eq('my_course_handouts')
62
+ end
63
+
64
+ it "should abort if course dir is not found" do
65
+ Kernel.within 'my_course_handouts', true do
66
+ err = capture_stderr do
67
+ expect(-> {subject.get_course_dir}).to raise_error(SystemExit)
68
+ end.uncolorize
69
+ expect(err).to eq("[ERROR] Lesson files were not found inside the provided directory. Aborting...\n")
70
+ end
71
+ end
51
72
  end
52
73
 
53
- it "should abort if course dir is not found" do
54
- Kernel.within 'my_course_handouts', true do
55
- err = capture_stderr do
56
- expect(-> {subject.get_course_dir}).to raise_error(SystemExit)
74
+ context "#generate_pdfs" do
75
+ it "should display proper messages" do
76
+ expect(course).to receive(:load_lessons!)
77
+ expect(course).to receive(:generate_pdfs)
78
+ info = capture_stdout do
79
+ subject.generate_pdfs(course)
57
80
  end.uncolorize
58
- expect(err).to eq("[ERROR] Lesson files were not found inside the provided directory. Aborting...\n")
81
+ expect(info).to eq("Starting to generate PDFs...\nPDFs for the course My Course were generated!\n#{'=' * 50}\n")
59
82
  end
60
83
  end
61
- end
62
84
 
63
- context "#build_index" do
64
- it "should display proper info messages" do
65
- info = capture_stdout do
66
- subject.build_index(course)
67
- end.uncolorize
68
- expect(info).to eq("Starting to build index...\nIndex for the My Course course is generated!\n#{'=' * 50}\n")
85
+ context "#build_index" do
86
+ it "should display proper info messages" do
87
+ info = capture_stdout do
88
+ subject.build_index(course)
89
+ end.uncolorize
90
+ expect(info).to eq("Starting to build index...\nIndex for the My Course course is generated!\n#{'=' * 50}\n")
91
+ end
92
+
93
+ it "should generate proper index" do
94
+ capture_stdout { subject.build_index(course) }
95
+ expect(IO.read('test.md')).to eq("# Index for the My Course course\n\n* [Lesson 1.3](my_course_handouts/lesson1.3.md)\n* [Lesson 2.5](my_course_handouts/lesson2.5.md)\n* [Lesson 5.8](my_course_handouts/lesson5.8.md)\n* [Lesson 10.2](my_course_handouts/lesson10.2.md)\n")
96
+ end
69
97
  end
70
98
 
71
- it "should generate proper index" do
72
- capture_stdout { subject.build_index(course) }
73
- expect(IO.read('test.md')).to eq("# Index for the My Course course\n\n* [Lesson 1.3](my_course_handouts/lesson1.3.md)\n* [Lesson 2.5](my_course_handouts/lesson2.5.md)\n* [Lesson 5.8](my_course_handouts/lesson5.8.md)\n* [Lesson 10.2](my_course_handouts/lesson10.2.md)\n")
99
+ context "#add_headings" do
100
+ it "should display proper info messages" do
101
+ info = capture_stdout do
102
+ subject.add_headings(course)
103
+ end.uncolorize
104
+ expect(info).to eq("Starting to add headings...\nHeadings for the lesson files of My Course course were added!\n#{'=' * 50}\n")
105
+ end
106
+
107
+ it "should generate proper index" do
108
+ capture_stdout { subject.add_headings(course) }
109
+ expect(IO.read('my_course_handouts/lesson10.2.md')).to eq("![](headings/lesson10.2.jpg)\n\n")
110
+ end
74
111
  end
75
112
  end
76
113
 
77
- context "#add_headings" do
78
- it "should display proper info messages" do
79
- info = capture_stdout do
80
- subject.add_headings(course)
81
- end.uncolorize
82
- expect(info).to eq("Starting to add headings...\nHeadings for the lesson files of My Course course were added!\n#{'=' * 50}\n")
83
- end
114
+ context "with clear directory" do
115
+ before(:all) { setup_env!(true) }
116
+ after(:all) { clear_env! }
84
117
 
85
- it "should generate proper index" do
86
- capture_stdout { subject.add_headings(course) }
87
- expect(IO.read('my_course_handouts/lesson10.2.md')).to eq("![](headings/lesson10.2.jpg)\n\n")
118
+ context "#generate_files" do
119
+ it "should display proper info messages" do
120
+ info = capture_stdout do
121
+ subject.generate_files(course)
122
+ end.uncolorize
123
+ expect(info).to eq("Starting to generate files...\nLesson files for the My Course course are generated!\n#{'=' * 50}\n")
124
+ end
125
+
126
+ it "should generate proper files" do
127
+ allow(subject.options).to receive(:lessons).and_return([1,2])
128
+ capture_stdout { subject.generate_files(course) }
129
+ expect(Dir.entries('my_course_handouts')).to include('lesson1-1.md', 'lesson2-1.md', 'lesson2-2.md')
130
+ expect(Dir.entries('my_course_handouts')).not_to include('lesson3-1.md', 'lesson2-3.md')
131
+ end
88
132
  end
89
133
  end
90
134
  end
data/spec/options_spec.rb CHANGED
@@ -10,10 +10,19 @@ RSpec.describe LessonsIndexer::Options do
10
10
  expect(options.headings).to be_falsey
11
11
  expect(options.headings_dir).to eq('headings')
12
12
  expect(options.pdf).to be_falsey
13
+ expect(options.lessons).to eq([])
14
+ expect(options).not_to respond_to(:help)
15
+ end
16
+
17
+ it "should raise an error if an unknown option is passed" do
18
+ err = capture_stderr do
19
+ expect( -> {described_class.new(['-u', 'test'])} ).to raise_error(SystemExit)
20
+ end.uncolorize
21
+ expect(err).to eq("[ERROR] unknown option `-u'\n")
13
22
  end
14
23
 
15
24
  it "should allow to override some options" do
16
- argv = ['-p', 'test_path', '-g', '-o', 'test.md']
25
+ argv = ['-p', 'test_path', '-g', '-o', 'test.md', '-l', '1,2,3']
17
26
  options = described_class.new(argv)
18
27
  expect(options.path).to eq('test_path')
19
28
  expect(options.output).to eq('test.md')
@@ -21,5 +30,6 @@ RSpec.describe LessonsIndexer::Options do
21
30
  expect(options.message).to eq('Added index')
22
31
  expect(options.all).to be_falsey
23
32
  expect(options.headings).to be_falsey
33
+ expect(options.lessons.length).to eq(3)
24
34
  end
25
35
  end
@@ -1,19 +1,21 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module SpecFilesSetup
4
- def setup_env!
4
+ def setup_env!(empty = false)
5
5
  FileUtils.mkdir_p('my_course_handouts/headings')
6
- lessons_array_with_incorrect.each do |file|
7
- File.new("my_course_handouts/#{file}", 'w+').close
8
- end
6
+ unless empty
7
+ lessons_array_with_incorrect.each do |file|
8
+ File.new("my_course_handouts/#{file}", 'w+').close
9
+ end
9
10
 
10
- headings_array_with_incorrect.each do |file|
11
- File.new("my_course_handouts/headings/#{file}", 'w+').close
11
+ headings_array_with_incorrect.each do |file|
12
+ File.new("my_course_handouts/headings/#{file}", 'w+').close
13
+ end
12
14
  end
13
15
  end
14
16
 
15
17
  def clear_env!
16
- FileUtils.remove_entry('my_course_handouts')
18
+ FileUtils.remove_entry('my_course_handouts', true)
17
19
  FileUtils.remove_entry('test.md', true)
18
20
  end
19
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lessons_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.0
61
+ version: 0.1.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.0
68
+ version: 0.1.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement