fronton 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/fronton.gemspec +7 -6
- data/lib/fronton.rb +3 -0
- data/lib/fronton/cli.rb +18 -157
- data/lib/fronton/commands/clean.rb +16 -0
- data/lib/fronton/commands/clobber.rb +21 -0
- data/lib/fronton/commands/compile.rb +43 -0
- data/lib/fronton/commands/info.rb +63 -0
- data/lib/fronton/commands/new.rb +20 -0
- data/lib/fronton/commands/server.rb +44 -0
- data/lib/fronton/config.rb +115 -93
- data/lib/fronton/contexts/sprockets.rb +38 -0
- data/lib/fronton/contexts/tilt.rb +24 -0
- data/lib/fronton/page.rb +9 -27
- data/lib/fronton/{html_server.rb → server.rb} +7 -7
- data/lib/fronton/version.rb +2 -2
- data/template/fronton.yml +1 -1
- metadata +27 -7
- data/lib/fronton/assets_helpers.rb +0 -24
- data/lib/fronton/context.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a04f1ecd7b94cd1b50b9570f7ad5049e95447f
|
4
|
+
data.tar.gz: dd94d989deeeb470cc88388f254df9410f0c442c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d4684663e599a0a21824956518c1b0a53894936f394d5523da98585e4442e20087753bf61a53ee691c60722039cdc77435c895bd12d6e8c676cae543d143b75
|
7
|
+
data.tar.gz: 1458d67f6a156d35d393837c8a57150218e47c8264fd082e64b8f8f1b5744db64c235344e64f068e52f53554eb1d94a3faee27591d484de69e2cfb249636bfdd
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ assets_paths:
|
|
60
60
|
- vendor/stylesheets
|
61
61
|
- vendor/fonts
|
62
62
|
- vendor/images
|
63
|
-
|
63
|
+
base_url: https://assets.example.com
|
64
64
|
compressors:
|
65
65
|
css: scss
|
66
66
|
js: uglifier
|
@@ -79,7 +79,7 @@ pages_paths:
|
|
79
79
|
| ------------- | ------ | ---------------------------------------------------------- |
|
80
80
|
| assets | Array | List of assets to compile (non js&css already included) |
|
81
81
|
| assets_paths | Array | List of directories where Sprockets find files for require |
|
82
|
-
|
|
82
|
+
| base_url | String | Base URL for assets in production |
|
83
83
|
| compressors | Hash | Hash with selected compressors by type |
|
84
84
|
| dependencies | Array | List of gems to install and require |
|
85
85
|
| fallback_page | String | Fallback page (i.e HTML5 mode in frontend routers) |
|
data/fronton.gemspec
CHANGED
@@ -28,12 +28,13 @@ Gem::Specification.new do |spec|
|
|
28
28
|
#
|
29
29
|
## DEPENDENCIES
|
30
30
|
#
|
31
|
-
spec.add_dependency 'activesupport',
|
32
|
-
spec.add_dependency '
|
33
|
-
spec.add_dependency 'rack
|
34
|
-
spec.add_dependency '
|
35
|
-
spec.add_dependency '
|
36
|
-
spec.add_dependency '
|
31
|
+
spec.add_dependency 'activesupport', '~> 4.2'
|
32
|
+
spec.add_dependency 'non-stupid-digest-assets', '~> 1.0'
|
33
|
+
spec.add_dependency 'rack', '~> 2.0'
|
34
|
+
spec.add_dependency 'rack-livereload', '~> 0.3'
|
35
|
+
spec.add_dependency 'sprockets', '~> 3.7'
|
36
|
+
spec.add_dependency 'tilt', '~> 2.0'
|
37
|
+
spec.add_dependency 'thor', '~> 0.19'
|
37
38
|
|
38
39
|
#
|
39
40
|
## DEVELOPMENT DEPENDENCIES
|
data/lib/fronton.rb
CHANGED
data/lib/fronton/cli.rb
CHANGED
@@ -1,172 +1,33 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'rack'
|
3
|
-
require 'rack/livereload'
|
4
1
|
require 'thor'
|
2
|
+
require 'active_support/concern'
|
5
3
|
require 'fronton/config'
|
6
|
-
require 'fronton/
|
4
|
+
require 'fronton/commands/new'
|
5
|
+
require 'fronton/commands/server'
|
6
|
+
require 'fronton/commands/compile'
|
7
|
+
require 'fronton/commands/clean'
|
8
|
+
require 'fronton/commands/clobber'
|
9
|
+
require 'fronton/commands/info'
|
7
10
|
|
8
11
|
module Fronton
|
9
|
-
class CLI < Thor
|
12
|
+
class CLI < Thor
|
10
13
|
include Thor::Actions
|
14
|
+
include Fronton::Commands::New
|
15
|
+
include Fronton::Commands::Server
|
16
|
+
include Fronton::Commands::Compile
|
17
|
+
include Fronton::Commands::Clean
|
18
|
+
include Fronton::Commands::Clobber
|
19
|
+
include Fronton::Commands::Info
|
11
20
|
|
12
|
-
|
13
|
-
File.expand_path('../../..', __FILE__)
|
14
|
-
end
|
21
|
+
Fronton::Config.load!
|
15
22
|
|
16
23
|
no_commands do
|
17
24
|
def config
|
18
|
-
|
19
|
-
@config = @config.call
|
20
|
-
else
|
21
|
-
@config
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize(*args)
|
27
|
-
super(*args)
|
28
|
-
@config = -> { Fronton::Config.load! }
|
29
|
-
end
|
30
|
-
|
31
|
-
desc 'new APP_NAME', 'Creates new frontend app'
|
32
|
-
def new(name)
|
33
|
-
if Dir.exist? name
|
34
|
-
say_status 'create', "#{name} directory already exists. Abort!", :red
|
35
|
-
exit 1
|
36
|
-
else
|
37
|
-
directory 'template', name
|
25
|
+
Fronton::Config
|
38
26
|
end
|
39
27
|
end
|
40
28
|
|
41
|
-
|
42
|
-
|
43
|
-
method_option :port, type: :numeric, default: 3000, banner: 'PORT the port to bind to'
|
44
|
-
method_option :livereload, type: :boolean, default: false, banner: 'BOOLEAN enable or disable livereload support'
|
45
|
-
def server # rubocop:disable Metrics/AbcSize
|
46
|
-
# install dependencies for rails assets
|
47
|
-
config.install_dependencies
|
48
|
-
|
49
|
-
# require dependencies for rails assets
|
50
|
-
config.require_dependencies
|
51
|
-
|
52
|
-
# assets helpers
|
53
|
-
config.environment.context_class.digest_assets = false
|
54
|
-
config.environment.context_class.assets_prefix = '/assets'
|
55
|
-
|
56
|
-
conf = config
|
57
|
-
opts = options
|
58
|
-
|
59
|
-
app = Rack::Builder.new do
|
60
|
-
map('/assets') { run conf.environment }
|
61
|
-
map('/') do
|
62
|
-
use Rack::LiveReload if opts[:livereload]
|
63
|
-
run Fronton::HTMLServer.new(config: conf)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
Rack::Server.start(
|
68
|
-
app: app,
|
69
|
-
environment: 'development',
|
70
|
-
Host: options[:host],
|
71
|
-
Port: options[:port]
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
desc 'compile', 'Compiles assets using digest and minification'
|
76
|
-
def compile # rubocop:disable Metrics/AbcSize
|
77
|
-
# install dependencies for rails assets
|
78
|
-
config.install_dependencies
|
79
|
-
|
80
|
-
# require dependencies for rails assets
|
81
|
-
config.require_dependencies
|
82
|
-
|
83
|
-
# configure environment
|
84
|
-
if config.compressor_js
|
85
|
-
config.environment.js_compressor = config.compressor_js.to_sym
|
86
|
-
end
|
87
|
-
|
88
|
-
if config.compressor_css
|
89
|
-
config.environment.css_compressor = config.compressor_css.to_sym
|
90
|
-
end
|
91
|
-
|
92
|
-
# assets helpers
|
93
|
-
prefix = "#{config.assets_url}/assets"
|
94
|
-
config.environment.context_class.digest_assets = true
|
95
|
-
config.environment.context_class.assets_prefix = prefix
|
96
|
-
|
97
|
-
# compile assets
|
98
|
-
config.manifest.compile(config.assets)
|
99
|
-
|
100
|
-
# compile html pages
|
101
|
-
config.pages.map(&:save)
|
102
|
-
end
|
103
|
-
|
104
|
-
desc 'clean', 'Remove old assets'
|
105
|
-
method_option :keep, type: :numeric, default: 2, banner: 'KEEP assets versions to keep'
|
106
|
-
def clean
|
107
|
-
config.manifest.clean(options[:keep])
|
108
|
-
end
|
109
|
-
|
110
|
-
desc 'clobber', 'Remove all assets'
|
111
|
-
def clobber
|
112
|
-
# assets
|
113
|
-
config.manifest.clobber
|
114
|
-
|
115
|
-
# html
|
116
|
-
FileUtils.rm Dir.glob(config.output.join('*.html'))
|
117
|
-
end
|
118
|
-
|
119
|
-
desc 'info', 'Information about project'
|
120
|
-
def info # rubocop:disable Metrics/AbcSize
|
121
|
-
say 'Dependencies', :bold
|
122
|
-
|
123
|
-
@dependencies = config.dependencies.map do |dep|
|
124
|
-
status = dep.available? ? 'Installed' : 'Not Installed'
|
125
|
-
[dep.name, dep.version, status]
|
126
|
-
end
|
127
|
-
|
128
|
-
print_table @dependencies
|
129
|
-
|
130
|
-
puts ''
|
131
|
-
|
132
|
-
say 'Assets Paths', :bold
|
133
|
-
config.assets_paths.each do |path|
|
134
|
-
say path.to_s, Dir.exist?(path) ? nil : :red
|
135
|
-
end
|
136
|
-
|
137
|
-
puts ''
|
138
|
-
|
139
|
-
say 'Pages Paths', :bold
|
140
|
-
config.pages_paths.each do |path|
|
141
|
-
say path.to_s, Dir.exist?(path) ? nil : :red
|
142
|
-
end
|
143
|
-
|
144
|
-
puts ''
|
145
|
-
|
146
|
-
say 'Sprockets Engines', :bold
|
147
|
-
|
148
|
-
@engines = config.environment.engines.map { |ext, klass| [ext, klass] }
|
149
|
-
print_table @engines
|
150
|
-
|
151
|
-
puts ''
|
152
|
-
|
153
|
-
say 'Compressors', :bold
|
154
|
-
|
155
|
-
@available_compressors = []
|
156
|
-
@used_compressors = [config.compressor_css.to_sym, config.compressor_js.to_sym]
|
157
|
-
|
158
|
-
config.environment.compressors.each do |mime, list|
|
159
|
-
list.each do |id, klass|
|
160
|
-
mark = @used_compressors.include?(id) ? '<--' : ''
|
161
|
-
@available_compressors << [mime, id, klass, mark]
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
print_table @available_compressors
|
166
|
-
|
167
|
-
puts ''
|
168
|
-
|
169
|
-
say "Powered by Fronton v#{Fronton.version} - https://github.com/javierav/fronton", :bold
|
29
|
+
def self.source_root
|
30
|
+
File.expand_path('../../..', __FILE__)
|
170
31
|
end
|
171
32
|
end
|
172
33
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Commands
|
3
|
+
module Clean
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'clean', 'Remove old assets'
|
8
|
+
method_option :keep, type: :numeric, default: 2, banner: 'KEEP assets versions to keep'
|
9
|
+
|
10
|
+
def clean
|
11
|
+
config.manifest.clean(options[:keep])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Fronton
|
4
|
+
module Commands
|
5
|
+
module Clobber
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
desc 'clobber', 'Remove all assets'
|
10
|
+
|
11
|
+
def clobber
|
12
|
+
# assets
|
13
|
+
config.manifest.clobber
|
14
|
+
|
15
|
+
# html
|
16
|
+
FileUtils.rm Dir.glob(config.output.join('*.html'))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Commands
|
3
|
+
module Compile
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'compile', 'Compile assets'
|
8
|
+
method_option :digest, type: :boolean, default: true, banner: 'BOOLEAN enable or disable assets digest'
|
9
|
+
method_option :compress, type: :boolean, default: true, banner: 'BOOLEAN enable or disable assets compression'
|
10
|
+
method_option :base, type: :boolean, default: true, banner: 'BOOLEAN enable or disable use of base_url in assets paths'
|
11
|
+
|
12
|
+
def compile # rubocop:disable Metrics/AbcSize
|
13
|
+
# install dependencies for rails assets
|
14
|
+
config.install_dependencies
|
15
|
+
|
16
|
+
# require dependencies for rails assets
|
17
|
+
config.require_dependencies
|
18
|
+
|
19
|
+
# configure environment
|
20
|
+
if config.compressor_js && options[:compress]
|
21
|
+
config.environment.js_compressor = config.compressor_js.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
if config.compressor_css && options[:compress]
|
25
|
+
config.environment.css_compressor = config.compressor_css.to_sym
|
26
|
+
end
|
27
|
+
|
28
|
+
# configuration
|
29
|
+
config.use_base = options[:base]
|
30
|
+
config.use_digest = options[:digest]
|
31
|
+
|
32
|
+
# compile assets
|
33
|
+
require 'non-stupid-digest-assets' unless options[:digest]
|
34
|
+
|
35
|
+
config.manifest.compile(config.assets)
|
36
|
+
|
37
|
+
# compile html pages
|
38
|
+
config.pages.each(&:save)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Commands
|
3
|
+
module Info
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'info', 'Display relevant information about a project'
|
8
|
+
|
9
|
+
def info # rubocop:disable Metrics/AbcSize
|
10
|
+
say 'Dependencies', :bold
|
11
|
+
|
12
|
+
@dependencies = config.dependencies.map do |dep|
|
13
|
+
status = dep.available? ? 'Installed' : 'Not Installed'
|
14
|
+
[dep.name, dep.version, status]
|
15
|
+
end
|
16
|
+
|
17
|
+
print_table @dependencies
|
18
|
+
|
19
|
+
puts ''
|
20
|
+
|
21
|
+
say 'Assets Paths', :bold
|
22
|
+
config.assets_paths.each do |path|
|
23
|
+
say path.to_s, Dir.exist?(path) ? nil : :red
|
24
|
+
end
|
25
|
+
|
26
|
+
puts ''
|
27
|
+
|
28
|
+
say 'Pages Paths', :bold
|
29
|
+
config.pages_paths.each do |path|
|
30
|
+
say path.to_s, Dir.exist?(path) ? nil : :red
|
31
|
+
end
|
32
|
+
|
33
|
+
puts ''
|
34
|
+
|
35
|
+
say 'Sprockets Engines', :bold
|
36
|
+
|
37
|
+
@engines = config.environment.engines.map { |ext, klass| [ext, klass] }
|
38
|
+
print_table @engines
|
39
|
+
|
40
|
+
puts ''
|
41
|
+
|
42
|
+
say 'Compressors', :bold
|
43
|
+
|
44
|
+
@available_compressors = []
|
45
|
+
@used_compressors = [config.compressor_css.to_sym, config.compressor_js.to_sym]
|
46
|
+
|
47
|
+
config.environment.compressors.each do |mime, list|
|
48
|
+
list.each do |id, klass|
|
49
|
+
mark = @used_compressors.include?(id) ? '<--' : ''
|
50
|
+
@available_compressors << [mime, id, klass, mark]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
print_table @available_compressors
|
55
|
+
|
56
|
+
puts ''
|
57
|
+
|
58
|
+
say "Powered by Fronton v#{Fronton.version} - https://github.com/javierav/fronton", :bold
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Commands
|
3
|
+
module New
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'new APP_NAME', 'Creates new frontend app'
|
8
|
+
|
9
|
+
def new(name)
|
10
|
+
if Dir.exist? name
|
11
|
+
say_status 'create', "#{name} directory already exists. Abort!", :red
|
12
|
+
exit 1
|
13
|
+
else
|
14
|
+
directory 'template', name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'rack/livereload'
|
3
|
+
require 'fronton/server'
|
4
|
+
|
5
|
+
module Fronton
|
6
|
+
module Commands
|
7
|
+
module Server
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
desc 'server', 'Preview your app in a browser'
|
12
|
+
method_option :host, type: :string, default: '127.0.0.1', banner: 'HOST the host address to bind to'
|
13
|
+
method_option :port, type: :numeric, default: 3000, banner: 'PORT the port to bind to'
|
14
|
+
method_option :livereload, type: :boolean, default: false, banner: 'BOOLEAN enable or disable livereload support'
|
15
|
+
|
16
|
+
def server # rubocop:disable Metrics/AbcSize
|
17
|
+
# install dependencies for rails assets
|
18
|
+
config.install_dependencies
|
19
|
+
|
20
|
+
# require dependencies for rails assets
|
21
|
+
config.require_dependencies
|
22
|
+
|
23
|
+
conf = config
|
24
|
+
opts = options
|
25
|
+
|
26
|
+
app = Rack::Builder.new do
|
27
|
+
map('/assets') { run conf.environment }
|
28
|
+
map('/') do
|
29
|
+
use Rack::LiveReload if opts[:livereload]
|
30
|
+
run Fronton::Server.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Rack::Server.start(
|
35
|
+
app: app,
|
36
|
+
environment: 'development',
|
37
|
+
Host: options[:host],
|
38
|
+
Port: options[:port]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/fronton/config.rb
CHANGED
@@ -2,8 +2,9 @@ require 'pathname'
|
|
2
2
|
require 'logger'
|
3
3
|
require 'yaml'
|
4
4
|
require 'sprockets'
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
6
|
require 'fronton/dependency'
|
6
|
-
require 'fronton/
|
7
|
+
require 'fronton/contexts/sprockets'
|
7
8
|
|
8
9
|
module Fronton
|
9
10
|
class Config
|
@@ -13,137 +14,158 @@ module Fronton
|
|
13
14
|
filename.start_with?(Dir.pwd) && !['.js', '.css', ''].include?(File.extname(logical_path))
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
class << self
|
18
|
+
attr_reader :logger
|
19
|
+
attr_writer :use_base, :use_digest, :assets_path
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def load!
|
22
|
+
file = working_dir.join('fronton.yml')
|
23
|
+
|
24
|
+
if file.exist?
|
25
|
+
@config = YAML.load_file(file).with_indifferent_access
|
26
|
+
@logger = Logger.new($stderr)
|
27
|
+
@logger.level = Logger::INFO
|
28
|
+
else
|
29
|
+
raise YAMLNotFound, "File 'fronton.yml' not found in #{Dir.pwd}"
|
30
|
+
end
|
23
31
|
end
|
24
|
-
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@logger.level = Logger::INFO
|
30
|
-
end
|
33
|
+
#
|
34
|
+
## ACCESSORS
|
35
|
+
#
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
def use_base
|
38
|
+
@use_base.nil? ? false : @use_base
|
39
|
+
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
assets_conf = @config['assets'].is_a?(Array) ? @config['assets'] : []
|
39
|
-
[PRECOMPILE_CRITERIA, /(?:\/|\\|\A)application\.(css|js)$/] + assets_conf
|
41
|
+
def use_digest
|
42
|
+
@use_digest.nil? ? false : @use_digest
|
40
43
|
end
|
41
|
-
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
def assets_path
|
46
|
+
@assets_path.nil? ? 'assets' : @assets_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def assets_prefix
|
50
|
+
use_base ? "#{base_url}/#{assets_path}" : assets_path
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
## YAML CONFIG
|
55
|
+
#
|
56
|
+
|
57
|
+
def assets
|
58
|
+
@assets ||= begin
|
59
|
+
assets_conf = @config[:assets].is_a?(Array) ? @config[:assets] : []
|
60
|
+
[PRECOMPILE_CRITERIA, %r{(?:/|\\|\A)application\.(css|js)$}] + assets_conf
|
49
61
|
end
|
50
62
|
end
|
51
|
-
end
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
64
|
+
def assets_paths
|
65
|
+
@assets_paths ||= begin
|
66
|
+
if @config[:assets_paths].is_a?(Array)
|
67
|
+
@config[:assets_paths].map { |p| working_dir.join(p) }
|
68
|
+
else
|
69
|
+
[]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
56
73
|
|
57
|
-
|
58
|
-
|
59
|
-
|
74
|
+
def base_url
|
75
|
+
@config[:base_url]
|
76
|
+
end
|
77
|
+
|
78
|
+
def output
|
79
|
+
@output ||= working_dir.join(@config[:output] || 'public')
|
80
|
+
end
|
60
81
|
|
61
|
-
|
62
|
-
|
63
|
-
|
82
|
+
def dependencies
|
83
|
+
@dependencies ||= begin
|
84
|
+
dep = @config[:dependencies].is_a?(Array) ? @config[:dependencies] : []
|
64
85
|
|
65
|
-
|
66
|
-
|
86
|
+
dep.map do |d|
|
87
|
+
Dependency.new(d.keys.first, d.values.first)
|
88
|
+
end
|
67
89
|
end
|
68
90
|
end
|
69
|
-
end
|
70
91
|
|
71
|
-
|
72
|
-
|
73
|
-
|
92
|
+
def fallback_page
|
93
|
+
if @config[:fallback_page]
|
94
|
+
Page.new(@config[:fallback_page], '/')
|
95
|
+
end
|
74
96
|
end
|
75
|
-
end
|
76
97
|
|
77
|
-
|
78
|
-
|
79
|
-
|
98
|
+
def pages
|
99
|
+
@pages ||= begin
|
100
|
+
pages = @config[:pages].is_a?(Array) ? @config[:pages] : []
|
80
101
|
|
81
|
-
|
82
|
-
|
102
|
+
pages.map do |page|
|
103
|
+
Page.new(page.keys.first, page.values.first)
|
104
|
+
end
|
83
105
|
end
|
84
106
|
end
|
85
|
-
end
|
86
107
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
108
|
+
def pages_paths
|
109
|
+
@pages_paths ||= begin
|
110
|
+
if @config[:pages_paths].is_a?(Array)
|
111
|
+
@config[:pages_paths].map { |p| working_dir.join(p) }
|
112
|
+
else
|
113
|
+
[]
|
114
|
+
end
|
93
115
|
end
|
94
116
|
end
|
95
|
-
end
|
96
117
|
|
97
|
-
|
98
|
-
|
99
|
-
|
118
|
+
def compressor_js
|
119
|
+
@config[:compressors] && @config[:compressors][:js]
|
120
|
+
end
|
100
121
|
|
101
|
-
|
102
|
-
|
103
|
-
|
122
|
+
def compressor_css
|
123
|
+
@config[:compressors] && @config[:compressors][:css]
|
124
|
+
end
|
104
125
|
|
105
|
-
|
106
|
-
|
107
|
-
|
126
|
+
def environment
|
127
|
+
@environment ||= begin
|
128
|
+
env = Sprockets::Environment.new
|
108
129
|
|
109
|
-
|
110
|
-
|
130
|
+
# logger
|
131
|
+
env.logger = logger
|
111
132
|
|
112
|
-
|
113
|
-
|
133
|
+
# fronton.yml assets paths
|
134
|
+
assets_paths.each { |path| env.append_path path }
|
114
135
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
136
|
+
# rails assets paths
|
137
|
+
if defined? RailsAssets
|
138
|
+
RailsAssets.load_paths.each { |path| env.append_path path }
|
139
|
+
end
|
119
140
|
|
120
|
-
|
121
|
-
|
141
|
+
# context helpers
|
142
|
+
env.context_class.send :include, ::Fronton::Contexts::Sprockets
|
122
143
|
|
123
|
-
|
144
|
+
env
|
145
|
+
end
|
124
146
|
end
|
125
|
-
end
|
126
147
|
|
127
|
-
|
128
|
-
|
129
|
-
|
148
|
+
def manifest
|
149
|
+
@manifest ||= Sprockets::Manifest.new environment, File.join(output, assets_path, 'manifest.json')
|
150
|
+
end
|
130
151
|
|
131
|
-
|
132
|
-
|
133
|
-
|
152
|
+
#
|
153
|
+
## METHODS
|
154
|
+
#
|
134
155
|
|
135
|
-
|
136
|
-
|
137
|
-
|
156
|
+
def install_dependencies
|
157
|
+
dependencies.map(&:install_dependency)
|
158
|
+
end
|
138
159
|
|
139
|
-
|
140
|
-
|
141
|
-
|
160
|
+
def require_dependencies
|
161
|
+
dependencies.map(&:require_dependency)
|
162
|
+
end
|
142
163
|
|
143
|
-
|
164
|
+
private
|
144
165
|
|
145
|
-
|
146
|
-
|
166
|
+
def working_dir
|
167
|
+
Pathname.pwd
|
168
|
+
end
|
147
169
|
end
|
148
170
|
end
|
149
171
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Contexts
|
3
|
+
module Sprockets
|
4
|
+
def asset_url(path, _options = {})
|
5
|
+
"url(#{asset_path(path)})"
|
6
|
+
end
|
7
|
+
alias_method :'asset-url', :asset_url
|
8
|
+
|
9
|
+
def asset_path(path, _options = {})
|
10
|
+
asset = link_asset(path)
|
11
|
+
digest_path = asset.digest_path
|
12
|
+
path = digest_path if config.use_digest
|
13
|
+
|
14
|
+
if current_prefix.empty?
|
15
|
+
path
|
16
|
+
else
|
17
|
+
"#{current_prefix}/#{path}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method :'asset-path', :asset_path
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# TODO, revisar esto para no tener logica aqui metida
|
25
|
+
def current_prefix
|
26
|
+
if !config.use_base && content_type == 'text/css'
|
27
|
+
''
|
28
|
+
else
|
29
|
+
config.assets_prefix
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def config
|
34
|
+
Fronton::Config
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Fronton
|
2
|
+
module Contexts
|
3
|
+
class Tilt
|
4
|
+
def javascript_tag(name)
|
5
|
+
%(<script src="#{asset_path("#{name}.js")}"></script>\n)
|
6
|
+
end
|
7
|
+
|
8
|
+
def stylesheet_tag(name)
|
9
|
+
%(<link href="#{asset_path("#{name}.css")}" media="screen" rel="stylesheet" />\n)
|
10
|
+
end
|
11
|
+
|
12
|
+
def asset_path(name)
|
13
|
+
asset_name = config.use_digest && config.manifest.assets[name] ? config.manifest.assets[name] : name
|
14
|
+
"#{config.assets_prefix}/#{asset_name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def config
|
20
|
+
Fronton::Config
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fronton/page.rb
CHANGED
@@ -1,28 +1,21 @@
|
|
1
1
|
require 'tilt'
|
2
|
-
require 'fronton/
|
2
|
+
require 'fronton/contexts/tilt'
|
3
3
|
|
4
4
|
module Fronton
|
5
5
|
class Page
|
6
|
-
attr_reader :name, :url
|
6
|
+
attr_reader :name, :url
|
7
7
|
|
8
|
-
def initialize(name, url
|
8
|
+
def initialize(name, url)
|
9
9
|
@name = name
|
10
|
-
@config = options.fetch(:config)
|
11
|
-
@digest = options.fetch(:digest, false)
|
12
|
-
@prefix = options.fetch(:prefix, '/assets')
|
13
10
|
@url = url
|
14
11
|
end
|
15
12
|
|
16
13
|
def content
|
17
|
-
Tilt.new(template_path, template_options).render(
|
14
|
+
Tilt.new(template_path, template_options).render(Fronton::Contexts::Tilt.new)
|
18
15
|
end
|
19
16
|
|
20
17
|
def save
|
21
|
-
|
22
|
-
with_prefix "#{config.assets_url}/assets" do
|
23
|
-
File.open(save_path, 'w') { |f| f.write(content) }
|
24
|
-
end
|
25
|
-
end
|
18
|
+
File.open(save_path, 'w') { |f| f.write(content) }
|
26
19
|
end
|
27
20
|
|
28
21
|
def exist?
|
@@ -31,6 +24,10 @@ module Fronton
|
|
31
24
|
|
32
25
|
private
|
33
26
|
|
27
|
+
def config
|
28
|
+
Fronton::Config
|
29
|
+
end
|
30
|
+
|
34
31
|
def template_path
|
35
32
|
found_path = config.pages_paths.find do |path|
|
36
33
|
File.exist?(path.join(name))
|
@@ -45,23 +42,8 @@ module Fronton
|
|
45
42
|
{ disable_escape: true, pretty: true }
|
46
43
|
end
|
47
44
|
|
48
|
-
def helpers_options
|
49
|
-
{ digest: @digest, manifest: @config.manifest, prefix: @prefix }
|
50
|
-
end
|
51
|
-
|
52
45
|
def save_path
|
53
46
|
config.output.join("#{File.basename(name, '.*')}.html")
|
54
47
|
end
|
55
|
-
|
56
|
-
def with_digest
|
57
|
-
@digest = true; yield; @digest = false # rubocop:disable Style/Semicolon
|
58
|
-
end
|
59
|
-
|
60
|
-
def with_prefix(prefix)
|
61
|
-
old_prefix = @prefix
|
62
|
-
@prefix = prefix
|
63
|
-
yield
|
64
|
-
@prefix = old_prefix
|
65
|
-
end
|
66
48
|
end
|
67
49
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
require 'fronton/page'
|
2
2
|
|
3
3
|
module Fronton
|
4
|
-
class
|
5
|
-
def initialize(options = {})
|
6
|
-
@config = options.fetch(:config)
|
7
|
-
end
|
8
|
-
|
4
|
+
class Server
|
9
5
|
# Rack entrypoint
|
10
6
|
def call(env)
|
11
7
|
if page = requested_page(env) # rubocop:disable Lint/AssignmentInCondition
|
@@ -16,7 +12,7 @@ module Fronton
|
|
16
12
|
error_404
|
17
13
|
end
|
18
14
|
else
|
19
|
-
fallback =
|
15
|
+
fallback = config.fallback_page
|
20
16
|
|
21
17
|
if fallback
|
22
18
|
render_page(fallback)
|
@@ -28,8 +24,12 @@ module Fronton
|
|
28
24
|
|
29
25
|
private
|
30
26
|
|
27
|
+
def config
|
28
|
+
Fronton::Config
|
29
|
+
end
|
30
|
+
|
31
31
|
def requested_page(env)
|
32
|
-
|
32
|
+
config.pages.find { |page| page.url == env['PATH_INFO'] }
|
33
33
|
end
|
34
34
|
|
35
35
|
def render_page(page)
|
data/lib/fronton/version.rb
CHANGED
data/template/fronton.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fronton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Aranda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: non-stupid-digest-assets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rack
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,13 +192,19 @@ files:
|
|
178
192
|
- bin/fronton
|
179
193
|
- fronton.gemspec
|
180
194
|
- lib/fronton.rb
|
181
|
-
- lib/fronton/assets_helpers.rb
|
182
195
|
- lib/fronton/cli.rb
|
196
|
+
- lib/fronton/commands/clean.rb
|
197
|
+
- lib/fronton/commands/clobber.rb
|
198
|
+
- lib/fronton/commands/compile.rb
|
199
|
+
- lib/fronton/commands/info.rb
|
200
|
+
- lib/fronton/commands/new.rb
|
201
|
+
- lib/fronton/commands/server.rb
|
183
202
|
- lib/fronton/config.rb
|
184
|
-
- lib/fronton/
|
203
|
+
- lib/fronton/contexts/sprockets.rb
|
204
|
+
- lib/fronton/contexts/tilt.rb
|
185
205
|
- lib/fronton/dependency.rb
|
186
|
-
- lib/fronton/html_server.rb
|
187
206
|
- lib/fronton/page.rb
|
207
|
+
- lib/fronton/server.rb
|
188
208
|
- lib/fronton/version.rb
|
189
209
|
- template/assets/fonts/.keep
|
190
210
|
- template/assets/images/.keep
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Fronton
|
2
|
-
class AssetsHelpers
|
3
|
-
def initialize(options = {})
|
4
|
-
@use_digest = options.fetch(:digest, false)
|
5
|
-
@prefix = options.fetch(:prefix)
|
6
|
-
@manifest = options.fetch(:manifest)
|
7
|
-
end
|
8
|
-
|
9
|
-
def javascript_tag(name)
|
10
|
-
name = asset_path("#{name}.js")
|
11
|
-
%(<script src="#{name}"></script>\n)
|
12
|
-
end
|
13
|
-
|
14
|
-
def stylesheet_tag(name)
|
15
|
-
name = asset_path("#{name}.css")
|
16
|
-
%(<link href="#{name}" media="screen" rel="stylesheet" />\n)
|
17
|
-
end
|
18
|
-
|
19
|
-
def asset_path(name)
|
20
|
-
asset_name = @use_digest && @manifest.assets[name] ? @manifest.assets[name] : name
|
21
|
-
File.join(@prefix, asset_name)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/fronton/context.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module Fronton
|
2
|
-
module Context
|
3
|
-
def self.included(klass)
|
4
|
-
klass.class_eval do
|
5
|
-
class_attribute :assets_prefix, :digest_assets
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def asset_url(path, _options = {})
|
10
|
-
"url(#{asset_path(path)})"
|
11
|
-
end
|
12
|
-
alias_method :'asset-url', :asset_url
|
13
|
-
|
14
|
-
def asset_path(path, _options = {})
|
15
|
-
asset = link_asset(path)
|
16
|
-
digest_path = asset.digest_path
|
17
|
-
path = digest_path if digest_assets
|
18
|
-
File.join(assets_prefix || "/", path)
|
19
|
-
end
|
20
|
-
alias_method :'asset-path', :asset_path
|
21
|
-
end
|
22
|
-
end
|