Package org.auraframework.def

Examples of org.auraframework.def.ThemeDef


        BuilderService builderService = Aura.getBuilderService();
        DefinitionService definitionService = Aura.getDefinitionService();
        String descriptors = (String) getAttributes().get("descriptor");
        String[] split = CreateComponentDefQuickFix.descriptorPattern.split(descriptors);
        for (String descriptor : split) {
            ThemeDef def = builderService.getThemeDefBuilder().setDescriptor(descriptor).build();
            definitionService.save(def);
            resetCache(def.getDescriptor());
        }
    }
View Full Code Here


    }

    @Override
    public Optional<Object> getValue(String name) throws QuickFixException {
        for (DefDescriptor<ThemeDef> theme : Lists.reverse(themes)) {
            ThemeDef def = theme.getDef();

            Optional<Object> value = def.getVar(name);
            if (value.isPresent()) {
                return value;
            }

            if (def.getMapProvider() != null) {
                value = Optional.<Object>fromNullable(dynamicVars.get(name, theme));
            }
            if (value.isPresent()) {
                return value;
            }
View Full Code Here

        themes.addAll(list);
        return this;
    }

    private void processNewTheme(DefDescriptor<ThemeDef> themeDescriptor) throws QuickFixException {
        ThemeDef def = themeDescriptor.getDef();
        if (def.getMapProvider() != null) {
            Map<String, String> map = def.getMapProvider().getDef().provide();
            for (Entry<String, String> entry : map.entrySet()) {
                dynamicVars.put(entry.getKey(), themeDescriptor, entry.getValue());
            }
        }
    }
View Full Code Here

        if (isCmpTheme && !imports.isEmpty()) {
            throw new InvalidDefinitionException("Component themes cannot import another theme", getLocation());
        }

        for (DefDescriptor<ThemeDef> theme : imports) {
            ThemeDef def = theme.getDef();

            // can't import a cmp theme
            if (def.isCmpTheme()) {
                String msg = String.format("Theme %s cannot be imported because it is a component theme", theme);
                throw new InvalidDefinitionException(msg, getLocation());
            }

            // can't import a theme with a parent. This is an arbitrary restriction to enforce a level of var lookup
            // simplicity and prevent misuse of imports.
            if (def.getExtendsDescriptor() != null) {
                String msg = String.format("Theme %s cannot be imported since it uses the 'extends' attribute", theme);
                throw new InvalidDefinitionException(msg, getLocation());
            }

            // can't import a theme that uses a provider.
            if (def.getDescriptorProvider() != null || def.getMapProvider() != null) {
                String msg = String.format("Theme %s cannot be imported since it uses a provider", theme);
                throw new InvalidDefinitionException(msg, getLocation());
            }
        }

        // vars
        for (VarDef def : vars.values()) {
            def.validateReferences();
        }

        // verify var cross references refer to something defined on this theme or on a parent theme. Or if this is a
        // cmp theme it can also refer to something on the namespace default theme.
        Iterable<String> names = getAllNames();
View Full Code Here

    public ThemeDefImplTest(String name) {
        super(name);
    }

    public void testEmptyTheme() throws QuickFixException {
        ThemeDef emptyThemeDef = addSeparateTheme("<aura:theme />").getDef(); // should parse without error
        Map<String, VarDef> vars = emptyThemeDef.getDeclaredVarDefs();
        assertTrue(vars.isEmpty());
        assertNull("Description should be null", emptyThemeDef.getDescription());
        assertNotNull("Name must be initialized", emptyThemeDef.getName());
    }
View Full Code Here

        assertNull("Description should be null", emptyThemeDef.getDescription());
        assertNotNull("Name must be initialized", emptyThemeDef.getName());
    }

    public void testThemeEquivalence() throws QuickFixException {
        ThemeDef theme1 = addSeparateTheme(theme().var("color", "red")).getDef();
        ThemeDef theme2 = addSeparateTheme(theme().var("color", "red")).getDef();
        assertTrue("expected theme1 to equal theme1", theme1.equals(theme1));
        assertFalse("expected theme1 unequal to theme2", theme1.equals(theme2));
        assertFalse("expected theme2 unequal to theme1", theme2.equals(theme1));
        assertFalse("expected theme1 not to equal null", theme1.equals(null));
    }
View Full Code Here

        DefDescriptor<ThemeDef> extendsSelf = addSourceAutoCleanup(ThemeDef.class, "");
        StringSource<?> source = (StringSource<?>) getAuraTestingUtil().getSource(extendsSelf);
        String contents = "<aura:theme extends='%s'> </aura:theme>";
        source.addOrUpdate(String.format(contents, extendsSelf.getDescriptorName()));
        try {
            ThemeDef def = extendsSelf.getDef();
            def.validateReferences();
            fail("A theme should not be able to extend itself.");
        } catch (Exception e) {
            checkExceptionContains(e, InvalidDefinitionException.class, "cannot extend itself");
        }
    }
View Full Code Here

        source = (StringSource<?>) getAuraTestingUtil().getSource(circular2);
        contents = "<aura:theme extends='%s'> </aura:theme>";
        source.addOrUpdate(String.format(contents, circular1.getDescriptorName()));

        try {
            ThemeDef def = circular2.getDef();
            def.getVar("attr");
            def.getAllNames(); // recursive
            fail("expected to throw InvalidDefinitionException");
        } catch (InvalidDefinitionException e) {
            checkExceptionContains(e, InvalidDefinitionException.class, "eventually extend itself");
        }
    }
View Full Code Here

    public ThemeDefHandlerTest(String name) {
        super(name);
    }

    public void testVars() throws Exception {
        ThemeDef def = addSeparateTheme(theme().var("test1", "1").var("test2", "2")).getDef();

        Map<String, VarDef> vars = def.getDeclaredVarDefs();
        assertEquals("didn't get expected number of vars", 2, vars.size());

        assertTrue("didn't find expected var", vars.containsKey("test1"));
        assertEquals("incorrect value for var", "2", vars.get("test2").getValue());
    }
View Full Code Here

                .var("var1", "1").var("var2", "2").var("var3", "3"));

        DefDescriptor<ThemeDef> import3 = addSeparateTheme(theme()
                .var("var1", "1").var("var2", "2").var("var3", "3"));

        ThemeDef def = addSeparateTheme(theme()
                .imported(import1)
                .imported(import2)
                .imported(import3))
                .getDef();

        List<DefDescriptor<ThemeDef>> imports = def.getDeclaredImports();
        assertEquals(3, imports.size());
    }
View Full Code Here

TOP

Related Classes of org.auraframework.def.ThemeDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.