# -*- coding: utf-8 -*-
from flask.ext.assets import Bundle
import os

__all__ = ['get_css_assets',
           'get_js_assets',
           'get_assets_by_category_and_type',
           'filter_by_extension',
           'assets_conversion_map',
           'static_files_folder',
           'component_file_name',
           ]

filter_by_extension = {
    "coffee": "coffeescript",
    "sass": "sass"
}

assets_conversion_map = {
    "coffee": "js",
    "sass": "css"
}

static_files_folder = "static"
component_file_name = "component.json"


def get_component_file_path():
    return os.path.join(static_files_folder, component_file_name)


def get_assets_files():
    return [get_component_file_path()]


from asset_helper import create_asset
from bower import get_libraries, get_appication, get_files


def get_assets_by_type(asset_type):
    vendor_assets = Bundle(*get_libraries()[asset_type])
    application_assets = Bundle(*[
        create_asset(asset)
        for asset in get_appication()[asset_type]
    ], output='gen/full.'+asset_type)
    return Bundle(vendor_assets, application_assets)


def get_assets_by_category_and_type(category, asset_type):
    return Bundle(*[
        create_asset(asset)
        for asset in get_files("category")[asset_type]
    ], output='gen/full.'+asset_type)


def get_css_assets():
    return get_assets_by_type("css")


def get_js_assets():
    return get_assets_by_type("js")

@@ -853,24 +853,16 @@
 ssets = 
-Bundle(*
 get_libr
@@ -872,21 +872,8 @@
 es()
-%5Basset_type%5D)
 %0A   
@@ -893,16 +893,148 @@
 assets =
+ get_appication()%0A    return Bundle(Bundle(*(vendor_assets()%5Basset_type%5D if asset_type in vendor_assets else %5B%5D)),%0A                 
  Bundle(
@@ -1028,32 +1028,46 @@
       Bundle(*%5B%0A
+              
         create_a
@@ -1070,32 +1070,46 @@
 te_asset(asset)%0A
+              
         for asse
@@ -1113,32 +1113,34 @@
 sset in 
-get_
 app
+l
 ication
-()
+_assets
 %5Basset_t
@@ -1136,32 +1136,46 @@
 ets%5Basset_type%5D%0A
+              
     %5D, output='g
@@ -1199,41 +1199,25 @@
 ype)
-%0A    return Bundle(vendor_assets,
+ if asset_type in
  app
@@ -1231,16 +1231,30 @@
 n_assets
+ else Bundle()
 )%0A%0A%0Adef 
@@ -1304,24 +1304,57 @@
 sset_type):%0A
+    assets = get_files(category)%0A
     return B
@@ -1415,29 +1415,14 @@
  in 
-get_files(%22category%22)
+assets
 %5Bass
@@ -1467,16 +1467,54 @@
 et_type)
+ if asset_type in assets else Bundle()
 %0A%0A%0Adef g

fix error with trying to reach non existed assets