marfa 0.0.3.9 → 0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 710e3c673087c7b47f6a4e00fba5e4f74821fcb0
4
- data.tar.gz: 049645723de6b540d9026704aa34575219a63b95
3
+ metadata.gz: 5bfc443e4ccb0a869cccb07907d0749cc9d3df3e
4
+ data.tar.gz: f745e7a1f995bf1e1856cf8b758178735075522f
5
5
  SHA512:
6
- metadata.gz: b5dba35208281137476e36436f13b0c288202bffe0405a59803a7f94bf0cf1342800ed1dbd748aab3321365bd494b0d476f1ae54e294bc0d0ce545f901b4a050
7
- data.tar.gz: 39ff0ce885d00eb46ac056d21ad61e9c33f794bca78e9c0f9d2b97a4ef68efa23c30795ef9b79f4ad33e4e32893feecc823370b2aedf6386ae4c2a493539ee24
6
+ metadata.gz: cbb28a82a8e8df3446183a02fca1839a3b88d48283d2392a3db3f2b3250c6685e3bb72add54f65d921509498760c2bde1f31a7cae4abaf39c72570a4a21424ec
7
+ data.tar.gz: cac62f610452d339ee115373b2ba24bc2ac186c1535f87c3b0a6c0107cb1b5ec48b3f383e5348b53156a24604da7982a9a8d09b9b38840f988c0216f8c997a02
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'rake'
3
+ require 'babel/transpiler'
4
+ require 'closure-compiler'
3
5
 
4
6
  include FileUtils
5
7
 
@@ -26,6 +28,8 @@ def create_marfa_config_file
26
28
  file.puts '# Static files content path'
27
29
  file.puts "Marfa.config.content_path = '/images/content/'"
28
30
  file.puts ''
31
+ file.puts 'Marfa.config.cache_styles = true'
32
+ file.puts ''
29
33
  file.puts '# Public folder'
30
34
  file.puts "Marfa.config.public_folder = File.expand_path('./static')"
31
35
  file.puts ''
@@ -36,7 +40,26 @@ def create_marfa_config_file
36
40
  file.puts 'Marfa.config.csrf_enabled = false'
37
41
  file.puts ''
38
42
  file.puts '# HTML Compression'
39
- file.puts 'Marfa.config.compression_enabled = false'
43
+ file.puts 'Marfa.config.html_compression_options = {'
44
+ file.puts ':enabled => true,
45
+ :remove_multi_spaces => true,
46
+ :remove_comments => true,
47
+ :remove_intertag_spaces => false,
48
+ :remove_quotes => true,
49
+ :compress_css => false,
50
+ :compress_javascript => false,
51
+ :simple_doctype => false,
52
+ :remove_script_attributes => true,
53
+ :remove_style_attributes => true,
54
+ :remove_link_attributes => true,
55
+ :remove_form_attributes => false,
56
+ :remove_input_attributes => true,
57
+ :remove_javascript_protocol => true,
58
+ :remove_http_protocol => false,
59
+ :remove_https_protocol => false,
60
+ :preserve_line_breaks => false,
61
+ :simple_boolean_attributes => true'
62
+ file.puts '}'
40
63
  file.puts ''
41
64
  file.puts '# CSS Minifying'
42
65
  file.puts 'Marfa.config.minify_css = true'
@@ -90,6 +113,12 @@ def create_bootstrap_file
90
113
  end
91
114
  end
92
115
 
116
+ def js_transpile(path, is_plain_text = true)
117
+ path = File.read(path) unless is_plain_text
118
+ result = Babel::Transpiler.transform(path)
119
+ result['code']
120
+ end
121
+
93
122
  task :default do
94
123
  puts 'Please specify command'
95
124
  end
@@ -120,6 +149,30 @@ task :start, [:home_path, :project_dir] do |t, args|
120
149
  create_bootstrap_file
121
150
  create_rackup_config_file
122
151
  puts 'Config files are created'
152
+ end
153
+ end
123
154
 
155
+ task :transpile_js, [:home_path, :search_dir, :output_dir] do |t, args|
156
+ puts 'Starting js transpile'
157
+
158
+ cd args[:home_path] + args[:search_dir], verbose: true
159
+
160
+ Dir[args[:home_path] + args[:search_dir] + '/**/*.js'].each do |path|
161
+ puts "Processing #{path}"
162
+
163
+ closure = Closure::Compiler.new(
164
+ compilation_level: 'SIMPLE_OPTIMIZATIONS',
165
+ language_out: 'ES5_STRICT'
166
+ )
167
+
168
+ code = js_transpile(path, false)
169
+ code = closure.compile(code)
170
+ output_path = args[:home_path] + args[:output_dir]
171
+ mkdir_p(output_path)
172
+
173
+ File.open(output_path + '/' + path.split('/').last, 'w') do |f|
174
+ f.puts code
175
+ end
124
176
  end
177
+
125
178
  end
data/bin/marfa CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  if ARGV.length > 1
5
5
  command = ARGV[0]
6
6
  rake_path = File.expand_path('../../Rakefile', __FILE__)
7
- system "rake -f #{rake_path} #{command}[#{FileUtils.pwd},#{ARGV[1]}]"
7
+ system "rake -f #{rake_path} #{command}[#{FileUtils.pwd},#{ARGV[1]},#{ARGV[2]}]"
8
8
 
9
9
  if $?.exitstatus > 0
10
10
  puts 'Failed'
@@ -31,9 +31,11 @@ module Marfa
31
31
 
32
32
  # Configure extending modules
33
33
  def self._configure_ext_modules(app)
34
+ opts = Marfa.config.html_compression_options
35
+
34
36
  app.configure do
35
37
  app.use Rack::Csrf, raise: true if Marfa.config.csrf_enabled
36
- app.use HtmlCompressor::Rack if Marfa.config.compression_enabled
38
+ app.use HtmlCompressor::Rack, opts if opts && opts[:enabled]
37
39
  end
38
40
  end
39
41
 
@@ -15,7 +15,7 @@ class String
15
15
  def to_class_name
16
16
  parts = downcase.split('/')
17
17
  parts.each(&:capitalize!)
18
- parts.join('')
18
+ parts.join('').gsub(%r{-}, '')
19
19
  end
20
20
 
21
21
  # Convert string to url part
@@ -48,7 +48,6 @@ module Marfa
48
48
  # render_block('index/index', ['tag1', 'tag2'])
49
49
  # @return [String] rendered block
50
50
  def render_component(path, tags = [])
51
-
52
51
  # TODO: Improve caching with parameters
53
52
  content = get_cached_content('block', path, tags)
54
53
  return content unless content.nil?
@@ -57,11 +56,12 @@ module Marfa
57
56
  return unless Object.const_defined?(classname)
58
57
 
59
58
  attrs = {
60
- user_data: @user_data || {},
61
- query: params.to_h
59
+ user_data: @user_data || {},
60
+ query: params.to_h
62
61
  }
63
62
 
64
63
  block = Object.const_get(classname).new
64
+
65
65
  data = block.get_data(attrs)
66
66
  cache_key = Marfa.cache.create_key('block', path, tags)
67
67
  full_path = 'components/' + path
@@ -85,8 +85,8 @@ module Marfa
85
85
  return unless Object.const_defined?(classname)
86
86
 
87
87
  attrs = {
88
- user_data: @user_data || {},
89
- query: params.to_h
88
+ user_data: @user_data || {},
89
+ query: params.to_h
90
90
  }
91
91
 
92
92
  block = Object.const_get(classname).new
@@ -1,6 +1,8 @@
1
1
  require 'babel/transpiler'
2
2
  require 'closure-compiler'
3
3
 
4
+ # TODO: Remove in v0.2
5
+
4
6
  # Javascript
5
7
  module Marfa
6
8
  # Helpers for Javascript
@@ -28,13 +30,13 @@ module Marfa
28
30
  end
29
31
 
30
32
  # https://developers.google.com/closure/compiler/docs/compilation_levels
31
- def js_import_from_haml(path)
33
+ def js_import_from_haml(path, data = {})
32
34
  closure = Closure::Compiler.new(
33
35
  compilation_level: 'SIMPLE_OPTIMIZATIONS',
34
36
  language_out: 'ES5_STRICT'
35
37
  )
36
38
 
37
- template = haml :"#{path}", :layout => false
39
+ template = haml :"#{path}", :layout => false, :locals => data
38
40
  code = js_transpile(template)
39
41
  code = closure.compile(code)
40
42
  '<script>' + code + '</script>'
@@ -1,5 +1,6 @@
1
1
  require 'sass/plugin'
2
2
  require 'csso'
3
+ require 'fileutils'
3
4
 
4
5
  # Rendering and caching style
5
6
  module Marfa
@@ -27,13 +28,14 @@ module Marfa
27
28
  return if options[:device].nil?
28
29
 
29
30
  root_path = options[:root_path] || '/'
31
+ path_to_css = settings.public_folder.to_s + '/css' + root_path
30
32
 
31
33
  file_name =
32
34
  [options[:section], options[:range], options[:device]]
33
35
  .reject { |opt| opt.nil? }
34
36
  .join('.') + '.css'
35
37
 
36
- path = settings.public_folder.to_s + '/css' + root_path + file_name
38
+ full_path = path_to_css + file_name
37
39
 
38
40
  scss_path =
39
41
  root_path +
@@ -41,11 +43,12 @@ module Marfa
41
43
  .reject { |opt| opt.nil? }
42
44
  .join('/')
43
45
 
44
- if File.exist?(path) && Marfa.config.cache_styles
45
- send_file(File.join(settings.public_folder.to_s + '/css', File.basename(file_name)), type: 'text/css')
46
+ if File.exist?(full_path) && Marfa.config.cache_styles
47
+ send_file(full_path, type: 'text/css')
46
48
  else
49
+ FileUtils.mkdir_p(path_to_css) unless Dir.exist?(path_to_css)
47
50
  styles = create_style(scss_path, options[:device])
48
- File.write(path, styles) if Marfa.config.cache_styles
51
+ File.write(full_path, styles) if Marfa.config.cache_styles
49
52
  content_type 'text/css', charset: 'utf-8', cache: 'false'
50
53
  styles
51
54
  end
data/lib/marfa/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Version constant
2
2
  module Marfa
3
3
  # The version constant for the current version of Marfa
4
- VERSION = '0.0.3.9' unless defined?(Marfa::VERSION)
4
+ VERSION = '0.1' unless defined?(Marfa::VERSION)
5
5
 
6
6
  # The current Marfa version.
7
7
  # @return [String] The version number
data/marfa.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'marfa'
6
- s.version = '0.0.3.9'
6
+ s.version = '0.1'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.date = Time.now.strftime('%Y-%m-%d')
9
9
  s.summary = 'Little Sinatra-based framework'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.9
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Krechetov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-01-27 00:00:00.000000000 Z
13
+ date: 2017-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml