gibier 0.8.3 → 0.8.4

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: b00f5bdac3730dd442ad8fe108003c6db327e107
4
- data.tar.gz: f196ced7e35638f7533960c59f89d461da948f49
3
+ metadata.gz: 38d858f7b0797998854b3948a5f04e4d06793438
4
+ data.tar.gz: 18c72c61d148fc0309fbfeff8497e108b35641e4
5
5
  SHA512:
6
- metadata.gz: 0cd79515cd3d9ca76dd09cf1d00743aeb32c37eabd9e651b83e0bcf28e94c447970235b0132d381bd7a6e7ff77153f8fee79fba2cb35deec2c282bf6987990ba
7
- data.tar.gz: dcf24093e83d5f3baf9004b3e0b477e9acfd088389473af568405db5907e53b774bcc86a4c243918596923c0dfe552d28ac16278b192e2b7da669cdec8ad9850
6
+ metadata.gz: 28a86fe0833d769463df42b946d2cd89e73f36b2a027bbbf5e82d9b48844b94aff9b3932205b871a9dbb2bf2d0bcb8cb7aeaf4383edf2939e363692c526caec8
7
+ data.tar.gz: ea91ba9ad40833a4d1f5979e65b9f06b63860c3eb743f97a53ad5b92218fa7a8f43dba756afe5a806d6d91533b618e7139ad82891f7f3707949d5e7de157069b
data/lib/gibier/cli.rb CHANGED
@@ -4,10 +4,14 @@ require 'pathname'
4
4
  require 'rouge'
5
5
  require 'opal'
6
6
  require 'haml'
7
+ require 'gibier/haml_helper'
8
+ require 'gibier/static_generator'
7
9
 
8
10
  module Gibier
9
11
  class Cli < Thor
10
- desc 'new', 'create new project'
12
+ include HamlHelper
13
+
14
+ desc 'new', 'Create new project'
11
15
 
12
16
  def new(name)
13
17
  puts "Create new project '#{name}'"
@@ -20,76 +24,32 @@ module Gibier
20
24
  end
21
25
  end
22
26
 
23
- desc 'highlight', 'generate highlight.css'
27
+ desc 'highlight', 'Generate highlight.css'
24
28
 
25
29
  def highlight
26
30
  puts Rouge::Themes::Base16.mode(:dark).render(scope: '.highlight')
27
31
  end
28
32
 
29
- desc 'ghpages', 'create static pages'
30
-
31
- def ghpages
32
- puts "Create static pages"
33
+ desc 'static', 'Create Static Pages'
34
+ option :name, type: :string, aliases: '-n', desc: 'Specify slide name'
35
+ option :dir, type: :string, aliases: '-d', desc: 'Specify target directory'
36
+ def static
37
+ puts "Create Static Pages"
33
38
 
34
- FileUtils.mkdir_p 'docs'
39
+ target_dir = options[:dir] || 'docs'
40
+ FileUtils.mkdir_p target_dir
35
41
  assets_dir = Dir.new(__dir__ + '/../../template/project/assets')
36
- FileUtils.cp_r(assets_dir.path, 'docs')
37
-
38
- slide_loader = Gibier::SlideLoader.new
39
- Gibier::SlideHelper.each_slides('data') do |name|
40
- slide_loader.init_slide(name)
41
-
42
- FileUtils.mkdir_p "docs/assets/#{name}"
43
- FileUtils.cp_r("data/#{name}/css", "docs/assets/#{name}")
44
- FileUtils.cp_r("data/#{name}/images", "docs/assets/#{name}")
45
-
46
- FileUtils.mkdir_p "docs/#{name}"
47
- convert_html(File.expand_path('../../../template/gh_pages/slide.haml', __FILE__), "docs/#{name}/index.html", slide_name: name)
48
-
49
- FileUtils.mkdir_p "docs/assets/#{name}/javascripts"
50
- build(name, "docs/assets/#{name}/javascripts/application.js")
51
- end
52
-
53
- convert_html(File.expand_path('../../../template/gh_pages/index.haml', __FILE__), "docs/index.html", slides: slide_loader.slides)
54
- end
42
+ FileUtils.cp_r(assets_dir.path, target_dir)
55
43
 
56
- private
57
-
58
- def convert_html(haml_file, html_file, **instance_vars)
59
- File.open(html_file, "w") do |f|
60
- engine = Haml::Engine.new(File.read(haml_file))
61
- context = Object.new
62
- instance_vars.each do |key, value|
63
- context.instance_variable_set(:"@#{key}", value)
64
- end
65
- f.write engine.render(context) # Tilt::StringTemplate.new().render
44
+ generator = StaticGenerator.new('data', target_dir)
45
+ if options[:name]
46
+ generator.generate_page(options[:name], 'assets', target_dir)
47
+ else
48
+ generator.generate_pages
66
49
  end
67
50
  end
68
51
 
69
- def build(name, filename)
70
- builder = Opal::Builder.new
71
-
72
- use_gem(builder, 'opal-browser', 'opal')
73
- use_gem(builder, 'opal-router', 'opal')
74
- use_gem(builder, 'hyalite', 'client')
75
-
76
- builder.append_paths './app'
77
- builder.use_gem 'gibier'
78
- builder.use_gem 'paggio'
79
- builder.build "./app/slides/#{name}/app.rb"
80
-
81
- File.open(filename, 'w') do |file|
82
- file.write builder.to_s
83
- end
84
-
85
- end
86
-
87
- def use_gem(builder, name, opal_path)
88
- spec = Gem::Specification.find_by_name name
89
- lib_path = Pathname.new spec.full_require_paths.first
90
- opal_path = lib_path.parent + opal_path
91
- builder.append_paths opal_path.to_s
92
- end
52
+ map ghpages: :static
93
53
  end
94
54
  end
95
55
 
@@ -0,0 +1,14 @@
1
+ module Gibier
2
+ module HamlHelper
3
+ def convert_html(haml_file, html_file, **instance_vars)
4
+ File.open(html_file, "w") do |f|
5
+ engine = Haml::Engine.new(File.read(haml_file))
6
+ context = Object.new
7
+ instance_vars.each do |key, value|
8
+ context.instance_variable_set(:"@#{key}", value)
9
+ end
10
+ f.write engine.render(context) # Tilt::StringTemplate.new().render
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,66 @@
1
+ module Gibier
2
+ class StaticGenerator
3
+ include HamlHelper
4
+
5
+ def initialize(data_dir, target_dir)
6
+ @data_dir = data_dir
7
+ @target_dir = target_dir
8
+ @slide_loader = Gibier::SlideLoader.new
9
+ end
10
+
11
+ def generate_pages(assets_path = 'assets')
12
+ Gibier::SlideHelper.each_slides(@data_dir) do |name|
13
+ generate_page(name, assets_path)
14
+ end
15
+
16
+ convert_html(File.expand_path('../../../template/gh_pages/index.haml', __FILE__), "docs/index.html", slides: @slide_loader.slides)
17
+ end
18
+
19
+ def generate_page(name, assets_path = 'assets', slide_dir = nil)
20
+ @slide_loader.init_slide(name)
21
+ src_dir = "#{@data_dir}/#{name}"
22
+
23
+ slide_dir = "#{@target_dir}/#{name}" unless slide_dir
24
+ FileUtils.mkdir_p slide_dir
25
+ slide_haml = File.expand_path('../../../template/gh_pages/slide.haml', __FILE__)
26
+ convert_html(slide_haml, "#{slide_dir}/index.html", slide_name: name, assets_path: assets_path)
27
+
28
+ assets_dir = "#{@target_dir}/assets/#{name}"
29
+ FileUtils.mkdir_p assets_dir
30
+
31
+ FileUtils.cp_r("#{src_dir}/css", assets_dir)
32
+ FileUtils.cp_r("#{src_dir}/images", assets_dir)
33
+
34
+ js_dir = "#{@target_dir}/assets/#{name}/javascripts"
35
+ FileUtils.mkdir_p js_dir
36
+ build(name, "#{js_dir}/application.js")
37
+ end
38
+
39
+ private
40
+
41
+ def build(name, filename)
42
+ builder = Opal::Builder.new
43
+
44
+ use_gem(builder, 'opal-browser', 'opal')
45
+ use_gem(builder, 'opal-router', 'opal')
46
+ use_gem(builder, 'hyalite', 'client')
47
+
48
+ builder.append_paths './app'
49
+ builder.use_gem 'gibier'
50
+ builder.use_gem 'paggio'
51
+ builder.build "./app/slides/#{name}/app.rb"
52
+
53
+ File.open(filename, 'w') do |file|
54
+ file.write builder.to_s
55
+ end
56
+
57
+ end
58
+
59
+ def use_gem(builder, name, opal_path)
60
+ spec = Gem::Specification.find_by_name name
61
+ lib_path = Pathname.new spec.full_require_paths.first
62
+ opal_path = lib_path.parent + opal_path
63
+ builder.append_paths opal_path.to_s
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module Gibier
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -3,9 +3,9 @@
3
3
  %head
4
4
  %meta{charset:"utf-8"}
5
5
  %title= @slide_name
6
- %link{rel:"stylesheet", href:"../assets/css/application.css"}
7
- %link{rel:"stylesheet", href:"../assets/#{@slide_name}/css/custom.css"}
8
- %link{rel:"stylesheet", href:"../assets/css/highlight.css"}
6
+ %link{rel:"stylesheet", href:"#{@assets_path}/css/application.css"}
7
+ %link{rel:"stylesheet", href:"#{@assets_path}/#{@slide_name}/css/custom.css"}
8
+ %link{rel:"stylesheet", href:"#{@assets_path}/css/highlight.css"}
9
9
 
10
10
  %body
11
11
  %section.gibier
@@ -13,6 +13,6 @@
13
13
  :javascript
14
14
  window.slideName = '#{@slide_name}'
15
15
  window.ghPages = true;
16
- window.assetsPath = '../assets/#{@slide_name}';
16
+ window.assetsPath = '#{@assets_path}/#{@slide_name}';
17
17
 
18
- %script{type:"text/javascript", src:"../assets/#{@slide_name}/javascripts/application.js"}
18
+ %script{type:"text/javascript", src:"#{@assets_path}/#{@slide_name}/javascripts/application.js"}
@@ -1,5 +1,6 @@
1
1
  require 'hyalite'
2
2
  require 'opal-router'
3
+ require 'browser'
3
4
  require 'browser/interval'
4
5
  require 'browser/location'
5
6
  require 'track_field'
@@ -97,11 +98,7 @@ module Gibier
97
98
  end
98
99
 
99
100
  def page_to(num)
100
- if Gibier.gh_pages
101
- $window.location.assign("./##{num}")
102
- else
103
- $window.location.assign("/#{Gibier.slide_name}##{num}")
104
- end
101
+ $window.location.assign("#{$window.location.to_s.sub(/#\d+$/, '')}##{num}")
105
102
  end
106
103
 
107
104
  def handle_key_down(event)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-19 00:00:00.000000000 Z
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -263,9 +263,11 @@ files:
263
263
  - bin/setup
264
264
  - lib/gibier.rb
265
265
  - lib/gibier/cli.rb
266
+ - lib/gibier/haml_helper.rb
266
267
  - lib/gibier/render.rb
267
268
  - lib/gibier/slide_helper.rb
268
269
  - lib/gibier/slide_loader.rb
270
+ - lib/gibier/static_generator.rb
269
271
  - lib/gibier/version.rb
270
272
  - template/app.rb
271
273
  - template/gh_pages/index.haml