Class: Isomorfeus::AssetManager::JsImport
- Inherits:
-
Object
- Object
- Isomorfeus::AssetManager::JsImport
- Defined in:
- lib/isomorfeus/asset_manager/js_import.rb
Instance Method Summary collapse
-
#initialize(package, js_constant = nil, imported_constants = nil, js_sub_constant = nil, import_assignment = nil) ⇒ JsImport
constructor
A new instance of JsImport.
- #to_s ⇒ Object
Constructor Details
#initialize(package, js_constant = nil, imported_constants = nil, js_sub_constant = nil, import_assignment = nil) ⇒ JsImport
Returns a new instance of JsImport.
4 5 6 7 8 9 10 |
# File 'lib/isomorfeus/asset_manager/js_import.rb', line 4 def initialize(package, js_constant = nil, imported_constants = nil, js_sub_constant = nil, import_assignment = nil) @package = package @js_constant = js_constant @js_sub_constant = js_sub_constant @imported_constants = imported_constants @import_assignment = import_assignment end |
Instance Method Details
#to_s ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/isomorfeus/asset_manager/js_import.rb', line 12 def to_s js = '' if @imported_constants if @js_sub_constant js << "import { #{@imported_constants} as #{@js_constant}_#{@js_sub_constant} } from \"#{@package}\";\n" else if @imported_constants.is_a?(String) if @imported_constants == '*' js << "import * as #{@js_constant} from \"#{@package}\";\n" else js << "import #{@imported_constants} from \"#{@package}\";\n" end else js << "import { #{@imported_constants.join(", ")} } from \"#{@package}\";\n" end end if @js_constant js << "if (!global.#{@js_constant}) { global.#{@js_constant} = {}; }\n" if @js_sub_constant if @js_constant if @js_sub_constant js << "global.#{@js_constant}.#{@js_sub_constant} = #{@js_constant}_#{@js_sub_constant};\n" else if @imported_constants.is_a?(String) if @imported_constants == '*' js << "global.#{@js_constant} = #{@js_constant};\n" else js << "global.#{@js_constant}.#{@import_assignment ? @import_assignment : @imported_constants} = #{@imported_constants};\n" end else @imported_constants.each do |imported_constant| js << "global.#{@js_constant}.#{@import_assignment ? @import_assignment : imported_constant} = #{imported_constant};\n" end end end end else @imported_constants.each do |imported_constant| js << "global.#{imported_constant} = #{imported_constant};\n" end end elsif @js_constant.nil? js << "import \"#{@package}\";\n" else js << "import #{@js_constant} from \"#{@package}\";\n" js << "global.#{@js_constant} = #{@js_constant};\n" end js end |