lessons_indexer 0.1.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 004cf03a3ec55d7e9a4df1a0f32b8aa54370dec1
4
- data.tar.gz: b6deb71e6bff1dd000089a95bf6a1fb0cecc36a0
3
+ metadata.gz: 066ca6597bddc89b3925da3df00a4732cfdc4977
4
+ data.tar.gz: 176a832789ba3064daeb96fac15c8de2abbdd31d
5
5
  SHA512:
6
- metadata.gz: 355197e5b247cd44cdc76e9037926ba7e8d1ae5d94c15eef7603c44910efccac38972369245951a2362c15c8f32dcf386b76b5e4c88658afca5fbac3c37ffe45
7
- data.tar.gz: 18fbaf874163e0409f5ec4f807f1a8764958719da44fb9b8879dbee288848d636ecc797cca58c09a4c546897da97db923f18830dfc94ee1ed575e7ad525f1dab
6
+ metadata.gz: 41ec1829cc6aa5c2e845189263a53e0e93080596f466a17f4ee1585734060f2f8057b44ea107c6e5496819978fe23699e5b0ca0de95d99c49f1bc2dbdd0e8a45
7
+ data.tar.gz: ca02f59549d1e92127b1ebeda8139c78ab18ce1dfefcd5acf57f9416ad39326fbbb795344e00fd5b4874ee6bd2670da4bb3b6257c7ae113f4a3f28f47050d42f
data/README.md CHANGED
@@ -51,6 +51,8 @@ is not set.
51
51
  has a heading in the beginning, it will be skipped.
52
52
  * `-d` (`--headings_dir`) - relative path to the directory with heading images.
53
53
  Defaults to `headings`, has no effect if the `-i` flag is not set.
54
+ * `-f` (`--pdf`) - should PDFs be generated from the lesson files in markdown format. PDFs will have the same name as the
55
+ lesson files, read more [below](#pdf-generation). Defauls to `false`.
54
56
 
55
57
  ## Some Assumptions
56
58
 
@@ -68,6 +70,32 @@ files (of course, they don't need to have the *.md* extension). Valid files name
68
70
  All other files will be ignored. If the program cannot find a header image for a specific step,
69
71
  this step will be just skipped and the corresponding warning message will be displayed.
70
72
 
73
+ ## PDF Generation
74
+
75
+ Starting from version **0.2.0** Indexer supports PDF generation. It is disabled by default - provide `-f` flag to enable this feature.
76
+
77
+ PDF generation is not a very simple process, so some additional software has to be installed on your machine:
78
+
79
+ * [Pandoc](http://pandoc.org/) - the main program that makes conversion possible. It supports all major platforms, just select the [version](http://pandoc.org/installing.html) that suits you.
80
+ * [LaTex](http://www.latex-project.org/). Unfortunately, it is not possible to convert directly to PDF, so LaTex is required. Pandoc [lists](http://pandoc.org/installing.html) the recommended
81
+ implementations of LaTex for various platforms.
82
+ * [xetex](http://xetex.sourceforge.net/) - extension for LaTex to integrate typesetting capabilities. By default changing the default
83
+ font family is a huge pain, therefore xetex is used. Please note, that it is already a part of some LaTex implementations
84
+ (for example, if you install full version of MIKTex, xetex will already be present, so no additional actions are needed).
85
+
86
+ Make sure Pandoc is present in your PATH by typing
87
+
88
+ ```
89
+ pandoc -v
90
+ ```
91
+
92
+ in your terminal.
93
+
94
+ Indexer uses [Open Sans](http://www.fontsquirrel.com/fonts/open-sans) as a main font and [Liberation Mono](http://www.fontsquirrel.com/fonts/Liberation-Mono) as monotype font (for code examples). Both of these fonts
95
+ are free (in contrast to Helvetica Neue that has to be purchased), so if you don't have those fonts just download them and install into the fonts directory.
96
+
97
+ After that you are ready to generate PDFs! Just remember that it will take some time (about 5-10 seconds per lesson file).
98
+
71
99
  ## Testing
72
100
 
73
101
  ```
@@ -29,6 +29,14 @@ module LessonsIndexer
29
29
  end
30
30
  end
31
31
 
32
+ def generate_pdfs
33
+ within(dir, true) do
34
+ lessons.list.sort.each do |lesson|
35
+ %x{pandoc #{lesson.file_name} -f markdown_github -o #{lesson.file_name.gsub(/md\z/i, '')}.pdf --variable geometry:"top=1.5cm, bottom=2.5cm, left=1.5cm, right=1.5cm" --latex-engine=xelatex --variable mainfont="Open Sans" --variable monofont="Liberation Mono" --variable fontsize="12pt"}
36
+ end
37
+ end
38
+ end
39
+
32
40
  def load_headings!
33
41
  within(dir + '/' + headings_dir, true) do
34
42
  @headings = HeadingsList.new(all_with_pattern(Heading::VERSION_PATTERN).map {|heading| Heading.new(heading)})
@@ -14,6 +14,7 @@ module LessonsIndexer
14
14
 
15
15
  build_index(course) unless options.skip_index
16
16
  add_headings(course) if options.headings
17
+ generate_pdfs(course) if options.pdf
17
18
  git_push! if options.git
18
19
  end
19
20
 
@@ -32,6 +33,13 @@ module LessonsIndexer
32
33
  end
33
34
  end
34
35
 
36
+ def generate_pdfs(course)
37
+ course.load_lessons!
38
+ with_messages("Starting to generate PDFs...", "PDFs for the course #{course.title} were generated!") do
39
+ course.generate_pdfs
40
+ end
41
+ end
42
+
35
43
  def get_course_dir
36
44
  dir = Dir.entries('.').detect {|el| el =~ /_handouts\z/i}
37
45
  exit_msg("Lesson files were not found inside the provided directory. Aborting...") if dir.nil?
@@ -26,6 +26,7 @@ module LessonsIndexer
26
26
  o.bool '-a', '--all', 'Work with all branches (except for master)', default: false
27
27
  o.bool '-i', '--headings', 'Add heading images to the beginning of the lesson files?', default: false
28
28
  o.string '-d', '--headings_dir', 'Relative path to the directory with heading images', default: 'headings'
29
+ o.bool '-f', '--pdf', 'Should PDFs be generated?', default: false
29
30
  end.to_hash
30
31
  rescue Slop::Error => e
31
32
  exit_msg e.message
@@ -1,3 +1,3 @@
1
1
  module LessonsIndexer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -22,6 +22,10 @@ RSpec.describe LessonsIndexer::Course do
22
22
  expect(subject.generate_index).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")
23
23
  end
24
24
 
25
+ specify "#generate_pdfs" do
26
+ expect(subject).to respond_to(:generate_pdfs)
27
+ end
28
+
25
29
  context "#generate_headings" do
26
30
  it "should return formatted heading and path to file" do
27
31
  expect(subject).to receive(:lessons).and_return(sample_lessons)
@@ -36,6 +36,13 @@ RSpec.describe LessonsIndexer::Indexer do
36
36
  expect(subject).not_to receive(:add_headings)
37
37
  capture_stdout { subject.do_work! }
38
38
  end
39
+
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! }
45
+ end
39
46
  end
40
47
 
41
48
  context "#get_course_dir" do
@@ -9,6 +9,7 @@ RSpec.describe LessonsIndexer::Options do
9
9
  expect(options.all).to be_falsey
10
10
  expect(options.headings).to be_falsey
11
11
  expect(options.headings_dir).to eq('headings')
12
+ expect(options.pdf).to be_falsey
12
13
  end
13
14
 
14
15
  it "should allow to override some options" do
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: 0.1.2
4
+ version: 0.2.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: 2015-05-17 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop