inesita 0.3.2 → 0.3.5

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: 128cb0e2fdec618eadbb291fe314c09e213a549a
4
- data.tar.gz: c72d4643eb7034aa29802104c8aac1a250f5174a
3
+ metadata.gz: f91a4d1e673a6b2193f21bc02f314badc654850a
4
+ data.tar.gz: dcc841d257a207e7a1d7f7fd7395ab9a4617ff88
5
5
  SHA512:
6
- metadata.gz: dd9a32e62454e2685c5772c7bb071351001447e951a99f9c01b77991f473804313051108a578c3a32c8a83266d66fab0174747fc7ee30922a7ee459bed839216
7
- data.tar.gz: 266c547fef5472b0b867ef14aad998c7b6f66cee8d01e03559d94dca6fd69bb62eba2bc1b29481c6ad9918f8591d2aadcb7a6c4a64f9a9882d8fe0e9308bcb20
6
+ metadata.gz: 636404d836f94c733888575ed7660e4d80764b4c0d4d532309bee232f888c871b5d70f67e73eb7db48139c13bafbd5229257bcd5d0b4ebd62610268182239352
7
+ data.tar.gz: 7e9b6bec1ab7f51753b67c267afbcc53b16cddd4d9c9c67cf6f29e37b0457cd16ec89bc8a19e83dd945ad8dab96f4d8e3fed73bd0f452517019637c192b64775
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## 0.3.5 (10.03.2016)
2
+ * add `inesita watch`
3
+ * add `inesita build` dir parameters
4
+
1
5
  ## 0.3.2 (05.03.2016)
2
6
  * add `app_dist` and `app_dev` directory support
3
- * add `redirect_to` to route option
7
+ * add `redirect_to` to `route` options
4
8
 
5
9
  ## 0.3.1 (05.01.2016)
6
10
  * add params hash to `router.url_for`
data/inesita.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'inesita'
3
- s.version = '0.3.2'
3
+ s.version = '0.3.5'
4
4
  s.authors = ['Michał Kalbarczyk']
5
5
  s.email = 'fazibear@gmail.com'
6
6
  s.homepage = 'http://github.com/inesita-rb/inesita'
data/lib/inesita.rb CHANGED
@@ -18,18 +18,6 @@ require 'inesita/server'
18
18
  module Inesita
19
19
  module_function
20
20
 
21
- def dist!
22
- @env = :dist
23
- end
24
-
25
- def dev?
26
- (@env || :dev) == :dev
27
- end
28
-
29
- def dist?
30
- @env == :dist
31
- end
32
-
33
21
  def assets_code
34
22
  @assets_code
35
23
  end
data/lib/inesita/cli.rb CHANGED
@@ -16,3 +16,4 @@ require 'inesita/minify'
16
16
  require 'inesita/cli/build'
17
17
  require 'inesita/cli/server'
18
18
  require 'inesita/cli/new'
19
+ require 'inesita/cli/watch'
@@ -8,51 +8,68 @@ class InesitaCLI < Thor
8
8
  desc 'build [OPTIONS]', 'Build Inesita app'
9
9
 
10
10
  method_option :force,
11
- aliases: ['-f'],
11
+ aliases: :f,
12
12
  default: false,
13
13
  desc: 'force overwrite'
14
14
 
15
- method_option :destination,
16
- aliases: ['-d', '-dir'],
15
+ method_option :destination_dir,
16
+ aliases: :d,
17
17
  default: Inesita::Config::BUILD_DIR,
18
- desc: 'build destination directory'
18
+ desc: 'destination directory'
19
19
 
20
- def build
21
- Inesita.dist!
22
- assets = Inesita::Server.new.assets_app
20
+ method_option :source_dir,
21
+ aliases: :s,
22
+ default: Inesita::Config::APP_DIR,
23
+ desc: 'source (app) dir'
24
+
25
+ method_option :static_dir,
26
+ aliases: :t,
27
+ default: Inesita::Config::STATIC_DIR,
28
+ desc: 'static dir'
23
29
 
24
- build_dir = options[:destination]
25
- force = options[:force]
30
+ method_option :dist_source_dir,
31
+ aliases: :b,
32
+ default: Inesita::Config::APP_DIST_DIR,
33
+ desc: 'source (app) dir for dist build'
26
34
 
27
- empty_directory build_dir, force: force
35
+ def build
36
+ assets = assets_server
37
+ empty_directory options[:destination_dir], force: options[:force]
28
38
 
29
- copy_static(build_dir, force)
30
- create_index(build_dir, assets['index.html'].source, force)
31
- create_js(build_dir, assets['application.js'].source, force)
32
- create_css(build_dir, assets['stylesheet.css'].source, force)
39
+ copy_static
40
+ create_asset(assets, 'index.html', ->(s) { Inesita::Minify.html(s) })
41
+ create_asset(assets, 'application.js', ->(s) { Inesita::Minify.js(s) })
42
+ create_asset(assets, 'stylesheet.css', ->(s) { Inesita::Minify.css(s) })
33
43
  end
34
44
 
35
45
  no_commands do
36
- def copy_static(build_dir, force)
37
- Dir.glob('./static/**/*').each do |file|
46
+ def assets_server
47
+ Inesita::Server.new({
48
+ dist: true,
49
+ static_dir: options[:static_dir],
50
+ app_dir: options[:source_dir],
51
+ app_dist_dir: options[:app_dist_dir]
52
+ }).assets_app
53
+ end
54
+
55
+ def copy_static
56
+ destination_dir = options[:destination_dir]
57
+ force = options[:force]
58
+ static_dir = options[:static_dir]
59
+
60
+ Dir.glob("./#{static_dir}/**/*").each do |file|
38
61
  if File.directory?(file)
39
- empty_directory File.join(build_dir, file), force: force
62
+ empty_directory File.join(destination_dir, file), force: force
40
63
  else
41
- copy_file File.absolute_path(file), File.join(build_dir, file), force: force
64
+ copy_file File.absolute_path(file), File.join(destination_dir, file.gsub(static_dir, 'static')), force: force
42
65
  end
43
66
  end
44
67
  end
45
68
 
46
- def create_index(build_dir, html, force)
47
- create_file File.join(build_dir, 'index.html'), Inesita::Minify.html(html), force: force
48
- end
49
-
50
- def create_js(build_dir, javascript, force)
51
- create_file File.join(build_dir, 'application.js'), Inesita::Minify.js(javascript), force: force
52
- end
53
-
54
- def create_css(build_dir, stylesheet, force)
55
- create_file File.join(build_dir, 'stylesheet.css'), Inesita::Minify.css(stylesheet), force: force
69
+ def create_asset(assets, name, minify_proc)
70
+ create_file File.join(options[:destination_dir], name),
71
+ minify_proc.call(assets[name].source),
72
+ force: options[:force]
56
73
  end
57
74
  end
58
75
  end
@@ -8,7 +8,7 @@ class InesitaCLI < Thor
8
8
  desc 'new PROJECT_NAME', 'Create Inesita app'
9
9
 
10
10
  method_option :force,
11
- aliases: ['-f'],
11
+ aliases: :f,
12
12
  default: false,
13
13
  desc: 'force overwrite'
14
14
 
@@ -5,12 +5,12 @@ class InesitaCLI < Thor
5
5
 
6
6
  desc 'server [OPTIONS]', 'Starts Inesita server'
7
7
  method_option :port,
8
- aliases: '-p',
8
+ aliases: :p,
9
9
  default: 9292,
10
10
  desc: 'The port Inesita will listen on'
11
11
 
12
12
  method_option :host,
13
- aliases: '-h',
13
+ aliases: :h,
14
14
  default: '127.0.0.1',
15
15
  desc: 'The host address Inesita will bind to'
16
16
 
@@ -1,6 +1,7 @@
1
1
  doctype html
2
2
  html
3
3
  head
4
+ meta charset="UTF-8"
4
5
  title <%= config[:project_name] %>
5
6
  == Inesita.assets_code
6
7
  body
@@ -0,0 +1,46 @@
1
+ class InesitaCLI < Thor
2
+ include Thor::Actions
3
+
4
+ check_unknown_options!
5
+
6
+ namespace :watch
7
+
8
+ desc 'watch [OPTIONS]', 'Watch files and build Inesita app'
9
+
10
+ method_option :force,
11
+ aliases: :f,
12
+ default: true,
13
+ desc: 'force overwrite'
14
+
15
+ method_option :destination_dir,
16
+ aliases: :d,
17
+ default: Inesita::Config::BUILD_DIR,
18
+ desc: 'destination directory'
19
+
20
+ method_option :source_dir,
21
+ aliases: :s,
22
+ default: Inesita::Config::APP_DIR,
23
+ desc: 'source (app) dir'
24
+
25
+ method_option :static_dir,
26
+ aliases: :t,
27
+ default: Inesita::Config::STATIC_DIR,
28
+ desc: 'static dir'
29
+
30
+ method_option :dist_source_dir,
31
+ aliases: :b,
32
+ default: Inesita::Config::APP_DIST_DIR,
33
+ desc: 'source (app) dir for dist build'
34
+
35
+ def watch
36
+ puts 'building...'
37
+ build
38
+ puts 'done.'
39
+ listener = Listen.to(options[:source_dir]) do |_modified, _added, _removed|
40
+ puts "rebuilding..."
41
+ build
42
+ puts "done."
43
+ end.start
44
+ loop { sleep 1000 }
45
+ end
46
+ end
@@ -10,27 +10,41 @@ module Inesita
10
10
  class Server
11
11
  attr_reader :assets_app
12
12
 
13
- def initialize
13
+ def initialize(opts = {})
14
+ setup_dirs(opts)
15
+ setup_env(opts)
14
16
  @assets_app = create_assets_app
15
17
  @source_maps_app = create_source_maps_app
16
18
  @app = create_app
17
19
  Inesita.assets_code = assets_code
18
20
  end
19
21
 
22
+ def setup_env(opts)
23
+ @dist = opts[:dist] || false
24
+ end
25
+
26
+ def setup_dirs(opts)
27
+ @static_dir = opts[:static_dir] || Config::STATIC_DIR
28
+ @app_dir = opts[:app_dir] || Config::APP_DIR
29
+ @app_dist_dir = opts[:app_dist_dir] || Config::APP_DIST_DIR
30
+ @app_dev_dir = opts[:app_dev_dir] || Config::APP_DEV_DIR
31
+ end
32
+
20
33
  def assets_code
21
- assets_prefix = Inesita.dev? ? Config::ASSETS_PREFIX : nil
34
+ assets_prefix = @dist ? nil : Config::ASSETS_PREFIX
22
35
  %(
23
36
  <link rel="stylesheet" type="text/css" href="#{assets_prefix}/stylesheet.css">
24
- #{Opal::Sprockets.javascript_include_tag('application', sprockets: @assets_app, prefix: assets_prefix, debug: Inesita.dev?)}
37
+ #{Opal::Sprockets.javascript_include_tag('application', sprockets: @assets_app, prefix: assets_prefix, debug: !@dist)}
25
38
  )
26
39
  end
27
40
 
28
41
  def create_app
29
42
  assets_app = @assets_app
30
43
  source_maps_app = @source_maps_app
44
+ static_dir = @static_dir
31
45
 
32
46
  Rack::Builder.new do
33
- use Rack::Static, :urls => [Config::STATIC_DIR]
47
+ use Rack::Static, :urls => [static_dir]
34
48
 
35
49
  use Rack::Rewrite do
36
50
  rewrite(/^(?!#{Config::ASSETS_PREFIX}|#{Config::SOURCE_MAP_PREFIX}).*/, Config::ASSETS_PREFIX)
@@ -48,9 +62,12 @@ module Inesita
48
62
 
49
63
  def create_assets_app
50
64
  Opal::Server.new do |s|
51
- s.append_path Config::APP_DIR
52
- s.append_path Config::APP_DIST_DIR if Inesita.dist?
53
- s.append_path Config::APP_DEV_DIR if Inesita.dev?
65
+ s.append_path @app_dir
66
+ if @dist
67
+ s.append_path @app_dist_dir
68
+ else
69
+ s.append_path @app_dev_dir
70
+ end
54
71
 
55
72
  Opal.paths.each do |p|
56
73
  s.append_path p
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inesita
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Kalbarczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -172,6 +172,7 @@ files:
172
172
  - lib/inesita/cli/template/app/stylesheet.css.sass.tt
173
173
  - lib/inesita/cli/template/config.ru.tt
174
174
  - lib/inesita/cli/template/static/inesita-rb.png
175
+ - lib/inesita/cli/watch.rb
175
176
  - lib/inesita/config.rb
176
177
  - lib/inesita/live_reload.rb
177
178
  - lib/inesita/minify.rb