hobby-pages 0.0.0 → 0.0.1

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: f742c6369b2e2a12560bdedff5e425d004c4a881
4
- data.tar.gz: 0720736511e432a6732b9aef7260cdef15987f8d
3
+ metadata.gz: bea29a23eae96509c273410272d0e9bb07172834
4
+ data.tar.gz: 4618afba5c3eea3db7c4a52f1011b8bedf109875
5
5
  SHA512:
6
- metadata.gz: 30f5d0cf472f37c08a398cfe31a931730f108a5c02a4e8cf3ae6997b79fe8f7cf5f5ddc1e2970e42c96a8d4de8ba2faacf4407a19984573a0be68817042b0db4
7
- data.tar.gz: 494eafecd9e4fd8edb15df02c94579e8b4bc40a23867b019252a08a0c1127f6fa6a0560246a0609ce58a0b4130fbd85755894178958b7741ca24bc2bd7aa5378
6
+ metadata.gz: e3abff4a15ae27a73e22e7562b01601bff58c3651e71131bf15f1dec781fa3dfea039c1edbf4af86dcdc339f2689bc633816d46a6ff8c1159bed901354eadcca
7
+ data.tar.gz: b6da58e1877baad6fe29c14e0ca649aa9ffc0e7ca6adfa9aa04041d19fe4a5531fa34eabb160b9c681ed47f6b3bc3daaefb0c6f12cc2e348a9104570de614128
data/hobby-pages.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |g|
2
2
  g.name = 'hobby-pages'
3
3
  g.files = `git ls-files`.split($/)
4
- g.version = '0.0.0'
4
+ g.version = '0.0.1'
5
5
  g.summary = 'A Hobby app to return a bunch of HTML pages from a directory.'
6
6
  g.authors = ['Anatoly Chernow']
7
7
 
@@ -9,4 +9,6 @@ Gem::Specification.new do |g|
9
9
  g.add_dependency 'tilt'
10
10
  g.add_dependency 'slim'
11
11
  g.add_dependency 'sass'
12
+ g.add_dependency 'sprockets'
13
+ g.add_dependency 'coffee-script'
12
14
  end
data/lib/hobby/pages.rb CHANGED
@@ -2,6 +2,8 @@ require 'hobby'
2
2
  require 'tilt'
3
3
  require 'slim'
4
4
  require 'sass'
5
+ require 'sprockets'
6
+ require 'coffee-script'
5
7
 
6
8
  module Hobby
7
9
  class Pages
@@ -39,12 +41,18 @@ module Hobby
39
41
  class Directory
40
42
  def initialize root
41
43
  @root = root
44
+
45
+ @sprockets = Sprockets::Environment.new
46
+ @sprockets.append_path "#{root}/js"
47
+
42
48
  @pages = Dir["#{root}/html/pages/*.slim"].map do |path|
43
49
  page = Page.new path, self
44
50
  [page.name, page]
45
51
  end.to_h
46
52
  end
47
53
 
54
+ attr_reader :sprockets
55
+
48
56
  def to_s
49
57
  @root
50
58
  end
@@ -84,13 +92,17 @@ module Hobby
84
92
  css = Sass::Engine.new(sass_string, load_paths: [load_path]).render
85
93
  @css_tag = "<style id='for_page_#{name}'>#{css}</style>"
86
94
  end
95
+
96
+ if js = directory.sprockets["pages/#{name}.js"]
97
+ @js_tag = "<script id='js_for_page_#{name}'>#{js}</script>"
98
+ end
87
99
  end
88
100
 
89
101
  def render app
90
102
  app.instance_eval @script if @script
91
103
 
92
104
  @layout.render app do
93
- "#{@css_tag}\n#{@template.render app}"
105
+ "#{@css_tag}#{@js_tag}#{@template.render app}"
94
106
  end
95
107
  end
96
108
  end
@@ -0,0 +1 @@
1
+ p something
@@ -0,0 +1 @@
1
+ alert 'something'
data/spec/main_spec.rb CHANGED
@@ -54,4 +54,17 @@ describe Hobby::Pages do
54
54
  text = doc.at_css('style#for_page_with-css').text
55
55
  expect(text).to eq "input {\n width: 100%; }\n"
56
56
  end
57
+
58
+ it 'creages pages with JS' do
59
+ response = @conn.get path: '/with-js'
60
+ doc = Nokogiri.HTML response.body
61
+
62
+ text = doc.at_css('script#js_for_page_with-js').text
63
+ expect(text).to eq <<~S
64
+ (function() {
65
+ alert('something');
66
+
67
+ }).call(this);
68
+ S
69
+ end
57
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobby-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2017-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hobby
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coffee-script
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description:
70
98
  email:
71
99
  executables: []
@@ -82,7 +110,9 @@ files:
82
110
  - spec/dirs/main/html/pages/exist.slim
83
111
  - spec/dirs/main/html/pages/with-css.slim
84
112
  - spec/dirs/main/html/pages/with-head.slim
113
+ - spec/dirs/main/html/pages/with-js.slim
85
114
  - spec/dirs/main/html/ruby/with-head.rb
115
+ - spec/dirs/main/js/pages/with-js.coffee
86
116
  - spec/helper.rb
87
117
  - spec/main_spec.rb
88
118
  homepage: