script 0.0.1 → 0.0.2

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: d3939afb4f888f22488699801765c07eda67ecf7
4
- data.tar.gz: ee9c375907906fee314aa7168f46e3018647f7ef
3
+ metadata.gz: 2dfd5efe6e5e7710e5d007dc9d46719bd6bc0edf
4
+ data.tar.gz: 0788cf8cc9e1d05310cb6e081b75124ade1889ed
5
5
  SHA512:
6
- metadata.gz: b47b155a3b3c62af4e71393364dfcb059822e198f0f0d16100409a6ba4dfc4d858596dc0417e15514ab0388082bb863382819518d2258e7ad165002fde4bfa7b
7
- data.tar.gz: e4f428b6477e984e4e8552aeedb41b1f7e0feee7cfef34d703999d2ccc32c318d9c240f8cafb783d16e0ee1845ecf3a06fc3204094014f83d5525f0cd636430b
6
+ metadata.gz: 561c94cffb4cd771696370f588219e8a33c3e2eb52adf093eb9f63610237de733c258ba524addd3bb1e51e73571a28e6d1669a49a91d92ab96cc3bc7ed2bf1f9
7
+ data.tar.gz: 0b1632aa572f972228dd530f705e2a11ae86842d25f7386724ee82e9d39ffb06aad86c2a847dcf89cb37074d69f59facda65d4ceadeb7e693f5af70b2234fcf0
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ script (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (9.0.6)
10
+ diff-lcs (1.3)
11
+ rake (10.4.2)
12
+ rspec (3.7.0)
13
+ rspec-core (~> 3.7.0)
14
+ rspec-expectations (~> 3.7.0)
15
+ rspec-mocks (~> 3.7.0)
16
+ rspec-core (3.7.0)
17
+ rspec-support (~> 3.7.0)
18
+ rspec-expectations (3.7.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-mocks (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-support (3.7.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.16)
31
+ byebug
32
+ rake (~> 10.0)
33
+ rspec (~> 3.0)
34
+ script!
35
+
36
+ BUNDLED WITH
37
+ 1.16.0
data/README.md CHANGED
@@ -1,43 +1,91 @@
1
- # Script
1
+ # Script<img width="40" align="left" src="https://cdn.codementor.io/assets/topic/category_header/ruby-on-rails-bc9ab2af8d92eb4e7eb3211d548a09ad.png">
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/script`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ The Script is everything you need to make the most of Ruby as fabulous scripting language.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ * [Script](#script)
6
+ * [Setup](#setup)
7
+ * [Usage](#usage)
8
+ * [Contributing](#contributing)
9
+ * [License](#license)
10
+ * [Code of Conduct](#code-of-conduct)
6
11
 
7
- ## Installation
12
+ ## Setup
8
13
 
9
- Add this line to your application's Gemfile:
14
+ Install gem:
10
15
 
11
- ```ruby
12
- gem 'script'
16
+ ```
17
+ gem install script
13
18
  ```
14
19
 
15
- And then execute:
20
+ And require it in your script file:
16
21
 
17
- $ bundle
22
+ ```
23
+ require 'script'
24
+ ```
18
25
 
19
- Or install it yourself as:
26
+ ## Usage
20
27
 
21
- $ gem install script
28
+ ### Steps
22
29
 
23
- ## Usage
30
+ Reason about the step as a logical group of commands. Lets take for instance, the deploy script which builds a docker image, pushes it to Dockerhub and eventually creates the deployment on Kubernetes.
31
+
32
+ ```ruby
33
+ #!/usr/local/bin/ruby
34
+
35
+ require "script"
36
+
37
+ deploy = Script.new
38
+
39
+ deploy.step("Setup tools") do
40
+
41
+ `sudo apt-get install -y google-cloud-sdk kubectl`
42
+ `gcloud auth activate-service-account $GCLOUD_SERVICE_ACCOUNT_NAME`
43
+ `gcloud config set project dummy-project`
44
+ `gcloud container clusters get-credentials default --zone us-east`
45
+
46
+ end
47
+
48
+ deploy.step("Deploy docker image") do
24
49
 
25
- TODO: Write usage instructions here
50
+ `docker pull dummy`
51
+ `docker build --cache-from dummy -t dummy`
52
+ `docker build -t scripter/script .`
53
+ `docker push dummy`
54
+
55
+ end
26
56
 
27
- ## Development
57
+ deploy.step("Deploy to Kubernetes cluster") do
28
58
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+ `kubectl apply -f k8s.yml --record`
60
+
61
+ end
30
62
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+ # Finally, run the script
64
+
65
+ deploy.run
66
+ ```
67
+
68
+ The steps are run in order in which they are registered.
32
69
 
33
70
  ## Contributing
34
71
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/script. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
+ ```
73
+ # Clone the repo
74
+ git clone git@github.com:bmarkons/script.git
36
75
 
37
- ## License
76
+ # Install
77
+ bundle install
38
78
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
79
+ # Run tests
80
+ bundle exec rspec
81
+ ```
82
+
83
+ Pull requests are always welcome. In case you notice any bug or simply want to propose an improvement, please feel free to open an issue.
40
84
 
41
85
  ## Code of Conduct
42
86
 
43
- Everyone interacting in the Script project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/script/blob/master/CODE_OF_CONDUCT.md).
87
+ Please [be nice](https://github.com/bmarkons/script/blob/master/CODE_OF_CONDUCT.md).
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,21 @@
1
1
  require "script/version"
2
+ require "script/engine"
3
+ require "script/step"
2
4
 
3
- module Script
4
- # Your code goes here...
5
+ class Script
6
+ def initialize
7
+ @engine = Script::Engine.new
8
+ end
9
+
10
+ def engine
11
+ @engine
12
+ end
13
+
14
+ def step(headline, &block)
15
+ @engine.register_step(headline, block)
16
+ end
17
+
18
+ def run
19
+ @engine.run
20
+ end
5
21
  end
@@ -0,0 +1,19 @@
1
+ class Script::Engine
2
+ def initialize
3
+ @steps = []
4
+ end
5
+
6
+ def steps
7
+ @steps
8
+ end
9
+
10
+ def register_step(headline, block)
11
+ @steps << Script::Step.new(headline, block)
12
+ end
13
+
14
+ def run
15
+ @steps.each do |step|
16
+ step.run
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ class Script::Step
2
+ def initialize(headline, block)
3
+ @headline = headline
4
+ @block = block
5
+ end
6
+
7
+ def run
8
+ @block.call
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
- module Script
2
- VERSION = "0.0.1"
1
+ class Script
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.16"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "byebug"
27
28
  end
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env bash
2
+
3
+ #
4
+ # Steps:
5
+ #
6
+ # 1. Download corresponding html file for some README.md:
7
+ # curl -s $1
8
+ #
9
+ # 2. Discard rows where no substring 'user-content-' (github's markup):
10
+ # awk '/user-content-/ { ...
11
+ #
12
+ # 3.1 Get last number in each row like ' ... </span></a>sitemap.js</h1'.
13
+ # It's a level of the current header:
14
+ # substr($0, length($0), 1)
15
+ #
16
+ # 3.2 Get level from 3.1 and insert corresponding number of spaces before '*':
17
+ # sprintf("%*s", substr($0, length($0), 1)*3, " ")
18
+ #
19
+ # 4. Find head's text and insert it inside "* [ ... ]":
20
+ # substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
21
+ #
22
+ # 5. Find anchor and insert it inside "(...)":
23
+ # substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8)
24
+ #
25
+
26
+ gh_toc_version="0.4.9"
27
+
28
+ gh_user_agent="gh-md-toc v$gh_toc_version"
29
+
30
+ #
31
+ # Download rendered into html README.md by its url.
32
+ #
33
+ #
34
+ gh_toc_load() {
35
+ local gh_url=$1
36
+
37
+ if type curl &>/dev/null; then
38
+ curl --user-agent "$gh_user_agent" -s "$gh_url"
39
+ elif type wget &>/dev/null; then
40
+ wget --user-agent="$gh_user_agent" -qO- "$gh_url"
41
+ else
42
+ echo "Please, install 'curl' or 'wget' and try again."
43
+ exit 1
44
+ fi
45
+ }
46
+
47
+ #
48
+ # Converts local md file into html by GitHub
49
+ #
50
+ # ➥ curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown
51
+ # <p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>'"
52
+ gh_toc_md2html() {
53
+ local gh_file_md=$1
54
+ URL=https://api.github.com/markdown/raw
55
+ TOKEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt"
56
+ if [ -f "$TOKEN" ]; then
57
+ URL="$URL?access_token=$(cat $TOKEN)"
58
+ fi
59
+ curl -s --user-agent "$gh_user_agent" \
60
+ --data-binary @"$gh_file_md" -H "Content-Type:text/plain" \
61
+ $URL
62
+ }
63
+
64
+ #
65
+ # Is passed string url
66
+ #
67
+ gh_is_url() {
68
+ case $1 in
69
+ https* | http*)
70
+ echo "yes";;
71
+ *)
72
+ echo "no";;
73
+ esac
74
+ }
75
+
76
+ #
77
+ # TOC generator
78
+ #
79
+ gh_toc(){
80
+ local gh_src=$1
81
+ local gh_src_copy=$1
82
+ local gh_ttl_docs=$2
83
+
84
+ if [ "$gh_src" = "" ]; then
85
+ echo "Please, enter URL or local path for a README.md"
86
+ exit 1
87
+ fi
88
+
89
+
90
+ # Show "TOC" string only if working with one document
91
+ if [ "$gh_ttl_docs" = "1" ]; then
92
+
93
+ echo "Table of Contents"
94
+ echo "================="
95
+ echo ""
96
+ gh_src_copy=""
97
+
98
+ fi
99
+
100
+ if [ "$(gh_is_url "$gh_src")" == "yes" ]; then
101
+ gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy"
102
+ else
103
+ gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"
104
+ fi
105
+ }
106
+
107
+ #
108
+ # Grabber of the TOC from rendered html
109
+ #
110
+ # $1 — a source url of document.
111
+ # It's need if TOC is generated for multiple documents.
112
+ #
113
+ gh_toc_grab() {
114
+ # if closed <h[1-6]> is on the new line, then move it on the prev line
115
+ # for example:
116
+ # was: The command <code>foo1</code>
117
+ # </h1>
118
+ # became: The command <code>foo1</code></h1>
119
+ sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
120
+ # find strings that corresponds to template
121
+ grep -E -o '<a.*id="user-content-[^"]*".*</h[1-6]' |
122
+ # remove code tags
123
+ sed 's/<code>//' | sed 's/<\/code>//' |
124
+ # now all rows are like:
125
+ # <a id="user-content-..." href="..."><span ...></span></a> ... </h1
126
+ # format result line
127
+ # * $0 — whole string
128
+ echo -e "$(awk -v "gh_url=$1" '{
129
+ print sprintf("%*s", substr($0, length($0), 1)*3, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
130
+ }
131
+
132
+ #
133
+ # Returns filename only from full path or url
134
+ #
135
+ gh_toc_get_filename() {
136
+ echo "${1##*/}"
137
+ }
138
+
139
+ #
140
+ # Options hendlers
141
+ #
142
+ gh_toc_app() {
143
+ local app_name="gh-md-toc"
144
+
145
+ if [ "$1" = '--help' ] || [ $# -eq 0 ] ; then
146
+ echo "GitHub TOC generator ($app_name): $gh_toc_version"
147
+ echo ""
148
+ echo "Usage:"
149
+ echo " $app_name src [src] Create TOC for a README file (url or local path)"
150
+ echo " $app_name - Create TOC for markdown from STDIN"
151
+ echo " $app_name --help Show help"
152
+ echo " $app_name --version Show version"
153
+ return
154
+ fi
155
+
156
+ if [ "$1" = '--version' ]; then
157
+ echo "$gh_toc_version"
158
+ return
159
+ fi
160
+
161
+ if [ "$1" = "-" ]; then
162
+ if [ -z "$TMPDIR" ]; then
163
+ TMPDIR="/tmp"
164
+ elif [ -n "$TMPDIR" -a ! -d "$TMPDIR" ]; then
165
+ mkdir -p "$TMPDIR"
166
+ fi
167
+ local gh_tmp_md
168
+ gh_tmp_md=$(mktemp $TMPDIR/tmp.XXXXXX)
169
+ while read input; do
170
+ echo "$input" >> "$gh_tmp_md"
171
+ done
172
+ gh_toc_md2html "$gh_tmp_md" | gh_toc_grab ""
173
+ return
174
+ fi
175
+
176
+ for md in "$@"
177
+ do
178
+ echo ""
179
+ gh_toc "$md" "$#"
180
+ done
181
+
182
+ echo ""
183
+ echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
184
+ }
185
+
186
+ #
187
+ # Entry point
188
+ #
189
+ gh_toc_app "$@"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bmarkons
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-15 00:00:00.000000000 Z
11
+ date: 2017-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: '"Gives you a hand with composing neat Ruby scripts."'
56
70
  email:
57
71
  - mamaveb@gmail.com
@@ -64,14 +78,18 @@ files:
64
78
  - ".travis.yml"
65
79
  - CODE_OF_CONDUCT.md
66
80
  - Gemfile
81
+ - Gemfile.lock
67
82
  - LICENSE.txt
68
83
  - README.md
69
84
  - Rakefile
70
85
  - bin/console
71
86
  - bin/setup
72
87
  - lib/script.rb
88
+ - lib/script/engine.rb
89
+ - lib/script/step.rb
73
90
  - lib/script/version.rb
74
91
  - script.gemspec
92
+ - scripts/gh-md-toc
75
93
  homepage: https://github.com/bmarkons/script
76
94
  licenses:
77
95
  - MIT