starter 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cf370bea371d92e0f522c20dbdb1fd37be5d6b4
4
+ data.tar.gz: b5a31f123a9087458e318386bf04f9ec251aa136
5
+ SHA512:
6
+ metadata.gz: c97531be24c2260bc15f0b9d8caf4687c66843ecf398bef46f84b82b93b66ed98631dcf902ddff21299cbfd50ba374a1f79a60bfe04c38db84e0235481d91fa8
7
+ data.tar.gz: 77b003f7d03ee93a905d364d9afe660dd688f5d154f39c00713768b359aa29529602df663625436086a63937c3b316e1a721c315d3b0c2ef94b546adef5448a1
@@ -0,0 +1,158 @@
1
+ module Starter
2
+
3
+ class Markdown
4
+
5
+
6
+ #Extender.process(
7
+ #:file => "path/to/template.md",
8
+ #:output => "path/to/output.md"
9
+ #)
10
+ #new_string = Extender.process(string)
11
+
12
+ module Extender
13
+
14
+ def self.process(arg)
15
+ if arg.is_a? String
16
+ string = arg
17
+ options = {}
18
+ else
19
+ options = arg
20
+ string = File.read arg[:file]
21
+ end
22
+ lines = string.split("\n")
23
+ out = FootnoteProcessor.new.process(lines)
24
+ out = CodeEmbedder.new.process(out)
25
+
26
+ processed = out.join("\n")
27
+ if path = options[:output]
28
+ File.open path, "w" do |f|
29
+ f.puts processed
30
+ end
31
+ end
32
+ processed
33
+ end
34
+
35
+ end
36
+
37
+ class CodeEmbedder
38
+ def initialize(options={})
39
+ @regex = %r{^```([^\s#]+)(#L(\S+))?\s*```$}
40
+ end
41
+
42
+
43
+ def process(lines)
44
+ # TODO: handle URLs
45
+ out = []
46
+ lines.each do |line|
47
+ if md = @regex.match(line)
48
+ _full, source_path, badline, line_spec = md.to_a
49
+ if line_spec
50
+ start, stop = line_spec.split("-").map { |s| s.to_i}
51
+ else
52
+ start = 1
53
+ end
54
+
55
+ source_path = File.expand_path(source_path).strip
56
+ extension = File.extname(source_path)
57
+ out << "```#{extension}\n\n"
58
+
59
+ embed = []
60
+ File.open(source_path, "r") do |source|
61
+ source.each_line do |line|
62
+ embed << line
63
+ end
64
+ end
65
+ start -= 1
66
+ if stop
67
+ stop -=1
68
+ else
69
+ stop = embed.size - 1
70
+ end
71
+ out << embed.slice(start..stop).join()
72
+ out << "```\n"
73
+ else
74
+ out << line
75
+ end
76
+ end
77
+ out
78
+ end
79
+
80
+ end
81
+
82
+ # Converts Pandoc-style footnotes into appropriate HTML
83
+ class FootnoteProcessor
84
+
85
+ def initialize(options={})
86
+ # looking for footnote refs like [^some_identifier]
87
+ @note_regex = /
88
+ ^
89
+ \[\^
90
+ ([\d\w\-_]+)
91
+ \]:
92
+ /x
93
+ @ref_regex = /
94
+ \[\^
95
+ ([\d\w\-_]+)
96
+ \]
97
+ /x
98
+ end
99
+
100
+ def process(lines)
101
+ out = []
102
+ refs = []
103
+ notes = {}
104
+ ref_counter = 0
105
+ while line = lines.shift
106
+ if md = @note_regex.match(line)
107
+ full, identifier = md.to_a
108
+ note = notes[identifier] = [line]
109
+ while (next_line = lines.shift) && next_line !~ /^\s*$/
110
+ note << next_line
111
+ end
112
+
113
+ elsif md = @ref_regex.match(line)
114
+ full, identifier = md.to_a
115
+ ref_counter += 1
116
+ refs << identifier
117
+ out << line.sub(full, format_ref(ref_counter, identifier))
118
+ else
119
+ out << line
120
+ end
121
+ end
122
+
123
+ if refs.size > 0
124
+ out << ""
125
+ out << "# Notes"
126
+ out << ""
127
+ refs.each_with_index do |identifier, index|
128
+ if note = notes[identifier]
129
+ start = note.shift
130
+ anchor = format_anchor(index + 1, identifier)
131
+ start.sub! /^\[.*\]: /, ""
132
+ out << "#{anchor} #{start}"
133
+
134
+ note.each do |line|
135
+ out << line
136
+ end
137
+ out << ""
138
+ end
139
+ end
140
+ end
141
+ out << ""
142
+ out
143
+ end
144
+
145
+
146
+ def format_anchor(number, identifier)
147
+ %Q{<a name="#{identifier}" href="#__#{identifier}">#{number} &#8617;</a>.}
148
+ end
149
+
150
+ def format_ref(number, identifier)
151
+ %Q{
152
+ <sup><a name="__#{identifier}" href="##{identifier}">#{number}</a>.</sup>
153
+ }.strip
154
+ end
155
+ end
156
+
157
+ end
158
+ end
@@ -1,14 +1,14 @@
1
1
  require "starter/tasks/starter"
2
2
 
3
- $STARTER[:directory] = File.basename(Dir.pwd)
4
- $STARTER[:gemspec_file] = "#{$STARTER[:directory]}.gemspec"
3
+ Starter.cache[:directory] = File.basename(Dir.pwd)
4
+ Starter.cache[:gemspec_file] = "#{Starter.cache[:directory]}.gemspec"
5
5
 
6
6
  desc "Bootstrap your project"
7
7
  task "bootstrap" => %w[ LICENSE ]
8
8
 
9
9
  file "LICENSE" => %w[ determine_author ] do
10
10
  File.open("LICENSE", "w") do |file|
11
- file.puts mit_license(:author => $STARTER[:author])
11
+ file.puts mit_license(:author => Starter.cache[:author])
12
12
  end
13
13
  end
14
14
 
@@ -1,6 +1,6 @@
1
1
  require "starter/tasks/starter"
2
2
 
3
- gemspec_path = FileList["*.gemspec"].first || "#{$STARTER[:directory]}.gemspec"
3
+ gemspec_path = FileList["*.gemspec"].first || "#{Starter.cache[:directory]}.gemspec"
4
4
  project_name = gemspec_path.chomp(".gemspec")
5
5
 
6
6
  task "bootstrap" => [ gemspec_path, "lib", "lib/#{project_name}.rb" ]
@@ -23,8 +23,8 @@ end
23
23
  file gemspec_path do |target|
24
24
  File.open(target.name, "w") do |file|
25
25
  file.puts gemspec_template(
26
- :author => $STARTER[:author],
27
- :project_name => $STARTER[:directory]
26
+ :author => Starter.cache[:author],
27
+ :project_name => Starter.cache[:directory]
28
28
  )
29
29
  end
30
30
  end
@@ -47,8 +47,9 @@ task "gem:push" do
47
47
  end
48
48
  end
49
49
 
50
+ desc "Install dependencies from the gemspec"
50
51
  task "gem:deps" => "read_gemspec" do
51
- gemspec = $STARTER[:gemspec]
52
+ gemspec = Starter.cache[:gemspec]
52
53
 
53
54
  require 'rubygems/dependency_installer'
54
55
  installer = Gem::DependencyInstaller.new
@@ -63,11 +64,11 @@ task "gem:deps" => "read_gemspec" do
63
64
  end
64
65
 
65
66
  task "version" => "read_gemspec" do
66
- $STARTER[:version] = $STARTER[:gemspec].version.version
67
+ Starter.cache[:version] = Starter.cache[:gemspec].version.version
67
68
  end
68
69
 
69
70
  task "read_gemspec" do
70
- $STARTER[:gemspec] = read_gemspec(gemspec_path)
71
+ Starter.cache[:gemspec] = read_gemspec(gemspec_path)
71
72
  end
72
73
 
73
74
  task "clean" do
@@ -6,7 +6,7 @@ desc "Create a git tag using the project version"
6
6
  # Note that the user of this library must ensure that a task named
7
7
  # "version" is defined before invocation time.
8
8
  task "git:tag" => "version" do
9
- version = $STARTER[:version]
9
+ version = Starter.cache[:version]
10
10
  git_tag = `git tag -l #{version}`.chomp
11
11
  if git_tag == version
12
12
  puts "Tag #{version} already exists. Bump your version."
@@ -3,7 +3,7 @@ require "starter/tasks/starter"
3
3
  desc "Create an issue on GitHub"
4
4
  task "github:issues:create" => "github_repo" do
5
5
 
6
- repo = $STARTER[:github_repo]
6
+ repo = Starter.cache[:github_repo]
7
7
  labels = repo.labels.map { |label| label["name"] }.join(" ")
8
8
  milestones = repo.milestones
9
9
 
@@ -64,7 +64,7 @@ end
64
64
 
65
65
  desc "show GitHub issues. Optional labels= and format="
66
66
  task "github:issues" => "github_repo" do
67
- repo = $STARTER[:github_repo]
67
+ repo = Starter.cache[:github_repo]
68
68
  options = {}
69
69
  require "pp"
70
70
  if labels = ENV["labels"] || ENV["label"]
@@ -85,7 +85,7 @@ end
85
85
 
86
86
  desc "show issues for current milestone on GitHub"
87
87
  task "github:milestones:current" => "github_repo" do
88
- repo = $STARTER[:github_repo]
88
+ repo = Starter.cache[:github_repo]
89
89
  milestones = repo.milestones
90
90
  sorted = milestones.sort_by {|m| m["due_on"] || "0" }
91
91
  current = sorted.last
@@ -106,7 +106,7 @@ end
106
106
  task "github_repo" => %w[ github_settings github_auth ] do
107
107
  require 'ghee'
108
108
 
109
- settings = $STARTER[:settings][:github]
109
+ settings = Starter.cache[:settings][:github]
110
110
  repo = settings[:repo]
111
111
  ghee = Ghee.access_token(settings[:auth])
112
112
 
@@ -115,7 +115,7 @@ task "github_repo" => %w[ github_settings github_auth ] do
115
115
  puts repo["message"]
116
116
  exit
117
117
  else
118
- $STARTER[:github_repo] = repo
118
+ Starter.cache[:github_repo] = repo
119
119
  end
120
120
 
121
121
  end
@@ -123,12 +123,12 @@ end
123
123
  task "github_auth" => %w[ github_settings .starter ] do
124
124
  require "starter/password"
125
125
  require 'ghee'
126
- settings = $STARTER[:settings][:github]
126
+ settings = Starter.cache[:settings][:github]
127
127
  if File.exists?(".starter/gh_auth") && auth = File.read(".starter/gh_auth")
128
128
  settings[:auth] = auth.chomp
129
129
  else
130
130
  password = Starter::Password.request("GitHub")
131
- user = $STARTER[:settings][:github][:user]
131
+ user = Starter.cache[:settings][:github][:user]
132
132
  auth = Ghee.create_token(user, password, ["user", "repo"])
133
133
  if auth
134
134
  settings[:auth] = auth
@@ -146,7 +146,7 @@ end
146
146
  task "read_settings" => ".starter" do
147
147
  require "yaml"
148
148
  begin
149
- $STARTER[:settings] = YAML.load_file(".starter/settings.yml")
149
+ Starter.cache[:settings] = YAML.load_file(".starter/settings.yml")
150
150
  rescue Errno::ENOENT
151
151
  $stderr.puts "You do not appear to have a .starter/settings.yml file."
152
152
  if Starter::Prompt.confirm("Create a stubbed settings file?")
@@ -154,7 +154,7 @@ task "read_settings" => ".starter" do
154
154
  settings = {
155
155
  :github => {
156
156
  :user => "YOURUSERNAME",
157
- :repo => {:owner => "OWNERNAME", :name => $STARTER[:directory]}
157
+ :repo => {:owner => "OWNERNAME", :name => Starter.cache[:directory]}
158
158
  }
159
159
  }
160
160
  YAML.dump(settings, f)
@@ -167,7 +167,7 @@ end
167
167
 
168
168
 
169
169
  task "github_settings" => "read_settings" do
170
- if $STARTER[:settings][:github] == nil
170
+ if Starter.cache[:settings][:github] == nil
171
171
  $stderr.puts "Looks like your .starter/settings.yml file isn't set up with a github stanza."
172
172
  exit
173
173
  end
@@ -4,7 +4,7 @@ task "bootstrap" => %w[ README.md ]
4
4
  file "README.md" do |target|
5
5
  File.open(target.name, "w") do |file|
6
6
  file.puts readme(
7
- :project_name => $STARTER[:directory]
7
+ :project_name => Starter.cache[:directory]
8
8
  )
9
9
  end
10
10
  end
@@ -11,12 +11,12 @@ desc "publish as an NPM package"
11
11
  task "release" => %w[ npm:publish ]
12
12
 
13
13
  task "npm:publish" => %w[ version ] do
14
- puts "Version in package.json is #{$STARTER[:version]}"
14
+ puts "Version in package.json is #{Starter.cache[:version]}"
15
15
  confirm_command("npm publish")
16
16
  end
17
17
 
18
18
  task "version" => "read_package" do
19
- $STARTER[:version] = $STARTER[:npm_package][:version]
19
+ Starter.cache[:version] = Starter.cache[:npm_package][:version]
20
20
  end
21
21
 
22
22
  # this seems like it ought to be a function? leaving it here because it seems
@@ -24,7 +24,7 @@ end
24
24
  task "read_package" do
25
25
  require "json"
26
26
  string = File.read("package.json")
27
- $STARTER[:npm_package] = JSON.parse(string, :symbolize_names => true)
27
+ Starter.cache[:npm_package] = JSON.parse(string, :symbolize_names => true)
28
28
  end
29
29
 
30
30
 
@@ -1,11 +1,17 @@
1
1
  require "pp"
2
+
3
+ module Starter
4
+ def self.cache
5
+ @cache ||= {}
6
+ end
7
+ end
8
+
2
9
  require "starter/prompt"
3
10
  require "starter/extensions/string"
4
11
  require "git"
5
12
 
6
- $STARTER ||= {}
7
13
 
8
- $STARTER[:directory] = File.basename(Dir.pwd)
14
+ Starter.cache[:directory] = File.basename(Dir.pwd)
9
15
 
10
16
  # Interface task declarations
11
17
 
@@ -22,17 +28,17 @@ task ".starter" do
22
28
  end
23
29
 
24
30
  task "determine_author" => %w[ read_git_config ] do
25
- if (git = $STARTER[:git]) && (author = git.config["user.name"])
26
- $STARTER[:author] = author
31
+ if (git = Starter.cache[:git]) && (author = git.config["user.name"])
32
+ Starter.cache[:author] = author
27
33
  else
28
- $STARTER[:author] = Starter::Prompt.prompt("Project author?")
34
+ Starter.cache[:author] = Starter::Prompt.prompt("Project author?")
29
35
  end
30
36
  end
31
37
 
32
38
  task "read_git_config" do
33
39
  if File.exist?(".git")
34
40
  g = Git.open(Dir.pwd)
35
- $STARTER[:git] = g
41
+ Starter.cache[:git] = g
36
42
  end
37
43
  end
38
44
 
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
5
- prerelease:
4
+ version: 0.1.11
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matthew King
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-30 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: git
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 1.2.6
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 1.2.6
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ghee
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: 0.9.11
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: 0.9.11
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: term-ansicolor
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: 1.3.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: 1.3.0
62
55
  description:
63
56
  email:
64
57
  executables: []
@@ -66,12 +59,13 @@ extensions: []
66
59
  extra_rdoc_files: []
67
60
  files:
68
61
  - LICENSE
69
- - Rakefile
70
62
  - README.md
63
+ - Rakefile
71
64
  - lib/starter/extensions/module.rb
72
65
  - lib/starter/extensions/string.rb
73
66
  - lib/starter/http.rb
74
67
  - lib/starter/markdown.rb
68
+ - lib/starter/markdown/extender.rb
75
69
  - lib/starter/misc.rb
76
70
  - lib/starter/mixins/statistics.rb
77
71
  - lib/starter/password.rb
@@ -86,26 +80,25 @@ files:
86
80
  - lib/starter/tasks/starter.rb
87
81
  homepage: https://github.com/automatthew/starter
88
82
  licenses: []
83
+ metadata: {}
89
84
  post_install_message:
90
85
  rdoc_options: []
91
86
  require_paths:
92
87
  - lib
93
88
  required_ruby_version: !ruby/object:Gem::Requirement
94
- none: false
95
89
  requirements:
96
- - - ! '>='
90
+ - - ">="
97
91
  - !ruby/object:Gem::Version
98
92
  version: '0'
99
93
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
94
  requirements:
102
- - - ! '>='
95
+ - - ">="
103
96
  - !ruby/object:Gem::Version
104
97
  version: '0'
105
98
  requirements: []
106
99
  rubyforge_project:
107
- rubygems_version: 1.8.23
100
+ rubygems_version: 2.2.0
108
101
  signing_key:
109
- specification_version: 3
102
+ specification_version: 4
110
103
  summary: Generally useful and reusable things
111
104
  test_files: []