hs-cli 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.hs.yml +2 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hs.gemspec +41 -0
- data/lib/hs/chapter.rb +31 -0
- data/lib/hs/config.rb +40 -0
- data/lib/hs/course.rb +35 -0
- data/lib/hs/elements/br.rb +9 -0
- data/lib/hs/elements/code.rb +22 -0
- data/lib/hs/elements/dd.rb +9 -0
- data/lib/hs/elements/dl.rb +9 -0
- data/lib/hs/elements/dt.rb +9 -0
- data/lib/hs/elements/element.rb +46 -0
- data/lib/hs/elements/emphasize.rb +9 -0
- data/lib/hs/elements/header.rb +16 -0
- data/lib/hs/elements/image.rb +22 -0
- data/lib/hs/elements/intro.rb +9 -0
- data/lib/hs/elements/li.rb +9 -0
- data/lib/hs/elements/link.rb +21 -0
- data/lib/hs/elements/note.rb +9 -0
- data/lib/hs/elements/ol.rb +9 -0
- data/lib/hs/elements/original.rb +9 -0
- data/lib/hs/elements/paragraph.rb +9 -0
- data/lib/hs/elements/strong.rb +9 -0
- data/lib/hs/elements/table.rb +39 -0
- data/lib/hs/elements/text.rb +21 -0
- data/lib/hs/elements/ul.rb +9 -0
- data/lib/hs/loaders/chapter_loader.rb +38 -0
- data/lib/hs/loaders/course_loader.rb +36 -0
- data/lib/hs/loaders/element_loader.rb +127 -0
- data/lib/hs/loaders/xml_parser.rb +62 -0
- data/lib/hs/preview/chapter_preview.rb +49 -0
- data/lib/hs/preview/course_preview.rb +43 -0
- data/lib/hs/preview/element_preview.rb +45 -0
- data/lib/hs/preview/html_preview.rb +27 -0
- data/lib/hs/version.rb +5 -0
- data/lib/hs.rb +28 -0
- metadata +231 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e1f1911dbebb05033050a47fb13af39c36f91381f8787aac030660fe93425d4a
|
4
|
+
data.tar.gz: 64a451d68bd3b611090bb95c997e6f1e8eed4e6c322325cae71fe84805a2b468
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 785b085c2b24c4f3a19da3fd39a5a9ff727698d057fb3394503471abb105b83c118fc04381327760813755e3d01586d598785bb753b456fe619e74dfa09ca463
|
7
|
+
data.tar.gz: 68c80f160635c6e63e2878e3b74cebe099d431aa538e1351afc132da41fa5b0cb5debe94bcf9d2d1c874455bc6ba98479740e77c3c6e13c01805213c081a8a6a
|
data/.gitignore
ADDED
data/.hs.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hs-cli (0.1.2)
|
5
|
+
activesupport (~> 5.2)
|
6
|
+
nokogiri (> 1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ast (2.4.0)
|
17
|
+
coderay (1.1.2)
|
18
|
+
concurrent-ruby (1.0.5)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
i18n (1.1.0)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
jaro_winkler (1.5.1)
|
23
|
+
method_source (0.9.0)
|
24
|
+
mini_portile2 (2.3.0)
|
25
|
+
minitest (5.11.3)
|
26
|
+
nokogiri (1.8.4)
|
27
|
+
mini_portile2 (~> 2.3.0)
|
28
|
+
parallel (1.12.1)
|
29
|
+
parser (2.5.1.2)
|
30
|
+
ast (~> 2.4.0)
|
31
|
+
powerpack (0.1.2)
|
32
|
+
pry (0.11.3)
|
33
|
+
coderay (~> 1.1.0)
|
34
|
+
method_source (~> 0.9.0)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (10.5.0)
|
37
|
+
rspec (3.8.0)
|
38
|
+
rspec-core (~> 3.8.0)
|
39
|
+
rspec-expectations (~> 3.8.0)
|
40
|
+
rspec-mocks (~> 3.8.0)
|
41
|
+
rspec-collection_matchers (1.1.3)
|
42
|
+
rspec-expectations (>= 2.99.0.beta1)
|
43
|
+
rspec-core (3.8.0)
|
44
|
+
rspec-support (~> 3.8.0)
|
45
|
+
rspec-expectations (3.8.1)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.8.0)
|
48
|
+
rspec-its (1.2.0)
|
49
|
+
rspec-core (>= 3.0.0)
|
50
|
+
rspec-expectations (>= 3.0.0)
|
51
|
+
rspec-mocks (3.8.0)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.8.0)
|
54
|
+
rspec-support (3.8.0)
|
55
|
+
rubocop (0.58.2)
|
56
|
+
jaro_winkler (~> 1.5.1)
|
57
|
+
parallel (~> 1.10)
|
58
|
+
parser (>= 2.5, != 2.5.1.1)
|
59
|
+
powerpack (~> 0.1)
|
60
|
+
rainbow (>= 2.2.2, < 4.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
63
|
+
rubocop-rspec (1.27.0)
|
64
|
+
rubocop (>= 0.56.0)
|
65
|
+
ruby-progressbar (1.10.0)
|
66
|
+
thread_safe (0.3.6)
|
67
|
+
tzinfo (1.2.5)
|
68
|
+
thread_safe (~> 0.1)
|
69
|
+
unicode-display_width (1.4.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
bundler (~> 1.16)
|
76
|
+
hs-cli!
|
77
|
+
pry (> 0.11)
|
78
|
+
rake (~> 10.0)
|
79
|
+
rspec (~> 3.0)
|
80
|
+
rspec-collection_matchers (~> 1.1)
|
81
|
+
rspec-its (~> 1.2)
|
82
|
+
rubocop (> 0.58)
|
83
|
+
rubocop-rspec (> 1.20)
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.16.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Dimitri Kurashvili
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/hackersrc/hs-cli.svg?branch=master)](https://travis-ci.org/hackersrc/hs-cli)
|
2
|
+
|
3
|
+
# HS
|
4
|
+
|
5
|
+
## ინსტალაცია
|
6
|
+
|
7
|
+
$ gem install hs-cli
|
8
|
+
|
9
|
+
## გამოყენება
|
10
|
+
|
11
|
+
### კონფიგურაცია
|
12
|
+
|
13
|
+
ფაილი `.hs` გამოიყენება კონფიგურაციის ჩასაწერად.
|
14
|
+
|
15
|
+
კონფიგურაციაში ჩაწერეთ თქვენი მომხარებელი და პაროლი,
|
16
|
+
რომლითაც ხართ რეგისტრირებული [ჰაკერების სკოლაში](http://hackerschool.ge).
|
17
|
+
|
18
|
+
USERNAME=dimitri
|
19
|
+
PASSWORD=secret
|
20
|
+
|
21
|
+
### ბრაძანებები
|
22
|
+
|
23
|
+
სტატიკური კურსის გენერაცია შეგიძლიათ ბრძანებით:
|
24
|
+
|
25
|
+
$ hs --out=html
|
26
|
+
|
27
|
+
კურსის ატვირთვა [ჰაკერების სკოლაში](http://hackerschool.ge):
|
28
|
+
|
29
|
+
$ hs --sync
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
34
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console`
|
35
|
+
for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
38
|
+
To release a new version, update the version number in `version.rb`,
|
39
|
+
and then run `bundle exec rake release`,
|
40
|
+
which will create a git tag for the version, push git commits and tags,
|
41
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub
|
46
|
+
at https://github.com/hackersrc/hs-cli.
|
47
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
48
|
+
and contributors are expected to adhere to the
|
49
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the
|
54
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RuboCop::RakeTask.new(:rubocop) do |t|
|
9
|
+
t.options = ['--display-cop-names']
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'hs'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require 'irb'
|
14
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hs.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'hs/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
8
|
+
spec.name = 'hs-cli'
|
9
|
+
spec.version = HS::VERSION
|
10
|
+
spec.authors = ['Dimitri Kurashvili']
|
11
|
+
spec.email = ['dimitri@hackerschool.ge']
|
12
|
+
|
13
|
+
spec.summary = 'HackerSchool client'
|
14
|
+
spec.description = 'Client for working on HackerSchool projects'
|
15
|
+
spec.homepage = 'http://github.com/hackersrc/hs-cli'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been
|
20
|
+
# added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'activesupport', '~> 5.2'
|
31
|
+
spec.add_dependency 'nokogiri', '> 1'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'pry', '> 0.11'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1'
|
38
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
39
|
+
spec.add_development_dependency 'rubocop', '> 0.58'
|
40
|
+
spec.add_development_dependency 'rubocop-rspec', '> 1.20'
|
41
|
+
end
|
data/lib/hs/chapter.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hs/loaders/chapter_loader'
|
4
|
+
require 'hs/preview/chapter_preview'
|
5
|
+
|
6
|
+
module HS
|
7
|
+
class Chapter
|
8
|
+
extend HS::ChapterLoader
|
9
|
+
include HS::ChapterPreview
|
10
|
+
|
11
|
+
def self.load(course, file)
|
12
|
+
load_chapter(course, File.read(file))
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :course, :content
|
16
|
+
attr_accessor :slug, :title, :intro
|
17
|
+
|
18
|
+
def initialize(course, args)
|
19
|
+
@course = course
|
20
|
+
@content = []
|
21
|
+
|
22
|
+
args.each do |key, val|
|
23
|
+
instance_variable_set("@#{key}", val)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def hs_url
|
28
|
+
"#{course.hs_url}/#{slug}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/hs/config.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module HS
|
7
|
+
class Config
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
DEFAULT_BASE_URL = 'http://hackerschool.ge'
|
11
|
+
DEFAULT_PREVIEW_DIR = 'previews'
|
12
|
+
|
13
|
+
def self.publish_url
|
14
|
+
instance.publish_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.preview_dir
|
18
|
+
instance.preview_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@data = load_configuration
|
23
|
+
end
|
24
|
+
|
25
|
+
def publish_url
|
26
|
+
@data['publish_url'] || DEFAULT_BASE_URL
|
27
|
+
end
|
28
|
+
|
29
|
+
def preview_dir
|
30
|
+
@data['preview_dir'] || DEFAULT_PREVIEW_DIR
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def load_configuration
|
36
|
+
return {} unless File.exist?('.hs.yml')
|
37
|
+
YAML.load_file('.hs.yml')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/hs/course.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hs/loaders/course_loader'
|
4
|
+
require 'hs/preview/course_preview'
|
5
|
+
|
6
|
+
module HS
|
7
|
+
class Course
|
8
|
+
extend HS::CourseLoader
|
9
|
+
include HS::CoursePreview
|
10
|
+
|
11
|
+
def self.load(file)
|
12
|
+
dir = File.dirname(file)
|
13
|
+
|
14
|
+
load_course(File.read(file)) do |course, chapter_file|
|
15
|
+
path = "#{dir}/#{chapter_file}"
|
16
|
+
course.chapters << HS::Chapter.load(course, path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :slug, :title
|
21
|
+
attr_reader :chapters
|
22
|
+
|
23
|
+
def initialize(args)
|
24
|
+
args.each do |key, val|
|
25
|
+
instance_variable_set("@#{key}", val)
|
26
|
+
end
|
27
|
+
|
28
|
+
@chapters = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def hs_url
|
32
|
+
"#{HS::Config.publish_url}/learn/#{slug}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HS
|
4
|
+
class Code < HS::Element
|
5
|
+
attr_accessor :lang
|
6
|
+
|
7
|
+
def inline?
|
8
|
+
lang.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def tag_name
|
12
|
+
inline? ? 'code' : 'pre'
|
13
|
+
end
|
14
|
+
|
15
|
+
def params
|
16
|
+
params = super
|
17
|
+
return params if inline?
|
18
|
+
|
19
|
+
params.merge(lang: lang)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hs/preview/element_preview'
|
4
|
+
|
5
|
+
module HS
|
6
|
+
class Element
|
7
|
+
include ElementPreview
|
8
|
+
|
9
|
+
attr_reader :children
|
10
|
+
attr_accessor :style, :class_name
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
args.each do |key, val|
|
14
|
+
instance_variable_set("@#{key}", val)
|
15
|
+
end
|
16
|
+
|
17
|
+
@children ||= []
|
18
|
+
end
|
19
|
+
|
20
|
+
def tag_name
|
21
|
+
'div'
|
22
|
+
end
|
23
|
+
|
24
|
+
def params
|
25
|
+
params = {}
|
26
|
+
class_name = element_class_name
|
27
|
+
params[:class] = class_name if class_name
|
28
|
+
params[:style] = style if style
|
29
|
+
|
30
|
+
params
|
31
|
+
end
|
32
|
+
|
33
|
+
def preview
|
34
|
+
element_preview(tag_name, params, children)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def element_class_name
|
40
|
+
return class_name unless respond_to?(:default_class)
|
41
|
+
|
42
|
+
class_names = [default_class, class_name].uniq.compact
|
43
|
+
class_names.join(' ') unless class_names.empty?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HS
|
4
|
+
class Image < HS::Element
|
5
|
+
attr_writer :src
|
6
|
+
|
7
|
+
def tag_name
|
8
|
+
'img'
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
super.merge(src: src)
|
13
|
+
end
|
14
|
+
|
15
|
+
def src
|
16
|
+
return unless @src
|
17
|
+
return @src if @src =~ %r{^http(s)?://}
|
18
|
+
return @src if @src.start_with?('/')
|
19
|
+
"/images/#{@src}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HS
|
4
|
+
class Link < HS::Element
|
5
|
+
attr_accessor :to
|
6
|
+
|
7
|
+
def tag_name
|
8
|
+
'a'
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
super.merge(href: href)
|
13
|
+
end
|
14
|
+
|
15
|
+
def href
|
16
|
+
return to if to =~ %r{^http(s)?://}
|
17
|
+
return to if to.start_with?('/')
|
18
|
+
"/#{to}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|