Example #1
0
    def load_assets(self):
        import os

        from frappe.modules import get_module_path, scrub

        self.script = ""

        page_name = scrub(self.name)

        path = os.path.join(get_module_path(self.module), "page", page_name)

        # script
        fpath = os.path.join(path, page_name + ".js")
        if os.path.exists(fpath):
            with open(fpath, "r") as f:
                self.script = render_include(f.read())
                self.script += f"\n\n//# sourceURL={page_name}.js"

        # css
        fpath = os.path.join(path, page_name + ".css")
        if os.path.exists(fpath):
            with open(fpath, "r") as f:
                self.style = safe_decode(f.read())

        # html as js template
        for fname in os.listdir(path):
            if fname.endswith(".html"):
                with open(os.path.join(path, fname), "r") as f:
                    template = f.read()
                    if "<!-- jinja -->" in template:
                        context = frappe._dict({})
                        try:
                            out = frappe.get_attr(
                                "{app}.{module}.page.{page}.{page}.get_context"
                                .format(app=frappe.local.module_app[scrub(
                                    self.module)],
                                        module=scrub(self.module),
                                        page=page_name))(context)

                            if out:
                                context = out
                        except (AttributeError, ImportError):
                            pass

                        template = frappe.render_template(template, context)
                    self.script = html_to_js_template(fname,
                                                      template) + self.script

                    # flag for not caching this page
                    self._dynamic_page = True

        if frappe.lang != "en":
            from frappe.translate import get_lang_js

            self.script += get_lang_js("page", self.name)

        for path in get_code_files_via_hooks("page_js", self.name):
            js = get_js(path)
            if js:
                self.script += "\n\n" + js
Example #2
0
	def load_assets(self):
		from frappe.modules import get_module_path, scrub
		import os

		path = os.path.join(get_module_path(self.module), 'page', scrub(self.name))

		# script
		fpath = os.path.join(path, scrub(self.name) + '.js')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.script = unicode(f.read(), "utf-8")

		# css
		fpath = os.path.join(path, scrub(self.name) + '.css')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.style = unicode(f.read(), "utf-8")

		# html as js template
		for fname in os.listdir(path):
			if fname.endswith(".html"):
				with open(os.path.join(path, fname), 'r') as f:
					template = unicode(f.read(), "utf-8")
					self.script = html_to_js_template(fname, template) + self.script

		if frappe.lang != 'en':
			from frappe.translate import get_lang_js
			self.script += get_lang_js("page", self.name)
Example #3
0
	def load_assets(self):
		from frappe.modules import get_module_path, scrub
		import os

		path = os.path.join(get_module_path(self.module), 'page', scrub(self.name))

		# script
		fpath = os.path.join(path, scrub(self.name) + '.js')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.script = f.read()

		# css
		fpath = os.path.join(path, scrub(self.name) + '.css')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.style = f.read()

		# html
		fpath = os.path.join(path, scrub(self.name) + '.html')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.content = f.read()

		if frappe.lang != 'en':
			from frappe.translate import get_lang_js
			self.script += get_lang_js("page", self.name)
Example #4
0
    def load_assets(self):
        from frappe.modules import get_module_path, scrub
        import os

        path = os.path.join(get_module_path(self.module), 'page',
                            scrub(self.name))

        # script
        fpath = os.path.join(path, scrub(self.name) + '.js')
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                self.script = unicode(f.read(), "utf-8")

        # css
        fpath = os.path.join(path, scrub(self.name) + '.css')
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                self.style = unicode(f.read(), "utf-8")

        # html as js template
        for fname in os.listdir(path):
            if fname.endswith(".html"):
                with open(os.path.join(path, fname), 'r') as f:
                    template = unicode(f.read(), "utf-8")
                    self.script = html_to_js_template(fname,
                                                      template) + self.script

        if frappe.lang != 'en':
            from frappe.translate import get_lang_js
            self.script += get_lang_js("page", self.name)
Example #5
0
    def load_assets(self):
        from frappe.modules import get_module_path, scrub
        import os

        path = os.path.join(get_module_path(self.module), "page", scrub(self.name))

        # script
        fpath = os.path.join(path, scrub(self.name) + ".js")
        if os.path.exists(fpath):
            with open(fpath, "r") as f:
                self.script = unicode(f.read(), "utf-8")

                # css
        fpath = os.path.join(path, scrub(self.name) + ".css")
        if os.path.exists(fpath):
            with open(fpath, "r") as f:
                self.style = unicode(f.read(), "utf-8")

                # html
        fpath = os.path.join(path, scrub(self.name) + ".html")
        if os.path.exists(fpath):
            with open(fpath, "r") as f:
                self.content = unicode(f.read(), "utf-8")

        if frappe.lang != "en":
            from frappe.translate import get_lang_js

            self.script += get_lang_js("page", self.name)
Example #6
0
	def load_assets(self):
		from frappe.modules import get_module_path, scrub
		import os
		self.script = ''

		page_name = scrub(self.name)

		path = os.path.join(get_module_path(self.module), 'page', page_name)

		# script
		fpath = os.path.join(path, page_name + '.js')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.script = render_include(f.read())

		# css
		fpath = os.path.join(path, page_name + '.css')
		if os.path.exists(fpath):
			with open(fpath, 'r') as f:
				self.style = safe_decode(f.read())

		# html as js template
		for fname in os.listdir(path):
			if fname.endswith(".html"):
				with open(os.path.join(path, fname), 'r') as f:
					template = f.read()
					if "<!-- jinja -->" in template:
						context = frappe._dict({})
						try:
							out = frappe.get_attr("{app}.{module}.page.{page}.{page}.get_context".format(
								app = frappe.local.module_app[scrub(self.module)],
								module = scrub(self.module),
								page = page_name
							))(context)

							if out:
								context = out
						except (AttributeError, ImportError):
							pass

						template = frappe.render_template(template, context)
					self.script = html_to_js_template(fname, template) + self.script

					# flag for not caching this page
					self._dynamic_page = True

		if frappe.lang != 'en':
			from frappe.translate import get_lang_js
			self.script += get_lang_js("page", self.name)

		for path in get_code_files_via_hooks("page_js", self.name):
			js = get_js(path)
			if js:
				self.script += "\n\n" + js
Example #7
0
    def load_assets(self):
        from frappe.modules import get_module_path, scrub
        import os

        page_name = scrub(self.name)

        path = os.path.join(get_module_path(self.module), 'page', page_name)

        # script
        fpath = os.path.join(path, page_name + '.js')
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                self.script = unicode(f.read(), "utf-8")

        # css
        fpath = os.path.join(path, page_name + '.css')
        if os.path.exists(fpath):
            with open(fpath, 'r') as f:
                self.style = unicode(f.read(), "utf-8")

        # html as js template
        for fname in os.listdir(path):
            if fname.endswith(".html"):
                with open(os.path.join(path, fname), 'r') as f:
                    template = unicode(f.read(), "utf-8")
                    if "<!-- jinja -->" in template:
                        context = frappe._dict({})
                        try:
                            out = frappe.get_attr(
                                "{app}.{module}.page.{page}.{page}.get_context"
                                .format(app=frappe.local.module_app[scrub(
                                    self.module)],
                                        module=scrub(self.module),
                                        page=page_name))(context)

                            if out:
                                context = out
                        except (AttributeError, ImportError):
                            pass

                        template = frappe.render_template(template, context)
                    self.script = html_to_js_template(fname,
                                                      template) + self.script

        if frappe.lang != 'en':
            from frappe.translate import get_lang_js
            self.script += get_lang_js("page", self.name)

        for path in get_code_files_via_hooks("page_js", self.name):
            js = get_js(path)
            if js:
                self.script += "\n\n" + js