lib/hyperstack/imports.rb in hyperstack-config-1.0.alpha1.4 vs lib/hyperstack/imports.rb in hyperstack-config-1.0.alpha1.5

- old
+ new

@@ -4,17 +4,21 @@ def import_list @import_list ||= [] end def import(value, gem: nil, cancelled: nil, client_only: nil, server_only: nil, tree: nil, js_import: nil, at_head: nil) - return if import_list.detect { |current_value, *_rest| value == current_value } + return if imported? value new_element = [ value, cancelled, !client_only, !server_only, (tree ? :tree : :gem), js_import ] import_list.send(at_head ? :unshift : :push, new_element) end + def imported?(value) + import_list.detect { |current_value, *| value == current_value } + end + alias imports import def import_tree(value, cancelled: nil, client_only: nil, server_only: nil) import(value, cancelled: cancelled, client_only: client_only, server_only: server_only, tree: true) end @@ -88,11 +92,11 @@ def generate_require_tree(path, render_on_server, render_on_client) base_name = Rails.root.join('app', path).to_s+'/' Dir.glob(Rails.root.join('app', path, '**', '*')).sort.collect do |fname| fname = fname.gsub(/^#{base_name}/, '') fname = fname.gsub(/\.erb$/, '') - if fname =~ /(\.js$)|(\.rb$)/ - fname = fname.gsub(/(\.js$)|(\.rb$)/, '') + if fname =~ /(\.js$)|(\.rb$)|(\.jsx$)/ + fname = fname.gsub(/(\.js$)|(\.rb$)|(\.jsx$)/, '') r = "require '#{fname}' #{client_guard(render_on_server, render_on_client)}" puts " #{r}" "puts \"#{r}\"; #{r}" end end.compact.join("\n")